CakePHP Paginator-> sort(__ d(不起作用

时间:2013-11-07 09:36:03

标签: cakephp plugins paginator

我有一个用i18n翻译的插件,在index.ctp中有分页符排序:

<?php echo $this->Paginator->sort(__d('item', 'item_layout_id')); ?>

当我尝试对列进行排序时,它们不会按顺序排列。

这是i18n的网址:

index/sort:Layout/direction:desc

而不是:

index/sort:item_layout_id/direction:desc

如何解决问题?

2 个答案:

答案 0 :(得分:0)

使用sort帮助paginator方法的方式是错误的,只需尝试这样做。

<?php $this->Paginator->sort('item_layout_id', __('item')); ?>

<?php $this->Paginator->sort('item_layout_id', __d('your_domain_name', 'item')); ?>

有关详细信息,请查看here

答案 1 :(得分:0)

您只传递一个参数来排序

The sort function

  

PaginatorHelper :: sort($ key,$ title = null,$ options = array())

问题中的代码是将变量fieldname传递给sort函数,它可以重写为:

<?php 
$translated = __d('item', 'item_layout_id');
echo $this->Paginator->sort($translated);

这意味着如果item_layout_id的翻译 - 排序链接将不再有效,因为字段Layout(来自问题)不存在。尝试按不存在的字段排序会导致参数被忽略。

正确使用

要翻译排序链接的标题 - 请使用title参数:

<?php 
echo $this->Paginator->sort(
    'item_layout_id', // Sort by this field
    __d('item', 'item_layout_id') // Display this text
);
相关问题