Cakephp 3 paginator sort fields with translate behavior i18n

自闭症网瘾萝莉.ら 提交于 2019-12-24 04:54:09

问题


I have a Posts table with Translate behavior and I want to sort it by title on the table at index view. I can't sort by the fields that are translated because the field's don't actually exist on the database. They exist on the i18n table.

This, as I explained above, doesn't work:

$this->Paginator->sort('title');
$this->Paginator->sort('Posts_title_translation.content');

So, what I should do? What am I missing?

Many Thanks!


回答1:


The second variant should work once the field is being whitelisted, which is generally necessary for associations to be used for sorting:

$this->paginate = [
    // ...
    'sortWhitelist' => [
        'Posts_title_translation.content',
        // ...
    ]
];

Note that with the whitelist in place, you will have to add all other fields of your Posts table that need to be used for sorting too!

See also Cookbook > ... Components > Pagination > Control which Fields Used for Ordering



来源:https://stackoverflow.com/questions/31424584/cakephp-3-paginator-sort-fields-with-translate-behavior-i18n

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!