加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

Cakephp 3.x另一个模型的排序不起作用

发布时间:2020-12-13 18:20:00 所属栏目:PHP教程 来源:网络整理
导读:我有两个型号用户角色 这里“Roles hasMany Users”和“Users areTo Roles” 当用户保存时,我们也会询问用户的角色记录保存. 问题: 我有列firstname,lastname,roles的用户列表.每个每列都有排序,但角色排序不起作用. 角色表包含??角色名称的“名称”字段.
我有两个型号用户&角色

这里“Roles hasMany Users”和“Users areTo Roles”

当用户保存时,我们也会询问用户的角色&记录保存.

问题:
我有列firstname,lastname,roles的用户列表.每个&每列都有排序,但角色排序不起作用.

角色表包含??角色名称的“名称”字段.
我在下面提到了链接,但它对我不起作用.
Pagination Sort in Cakephp 3.x

UsersController:

public function index() {
     $this->paginate = [
                'contain' => ['Roles'],'conditions' => [
                    'Users.user_type <>' => 1
                ]
            ];

            $this->set('users',$this->paginate($this->Users));
            $this->set('_serialize',['users']);
}

index.ctp

<tr>
                <th><?php echo $this->Paginator->sort('firstname',__('First Name')) ?></th>
                <th><?php echo $this->Paginator->sort('lastname',__('Last Name')) ?></th>
                <th><?php echo $this->Paginator->sort('email',__('Email Address')) ?></th>
                <th><?php echo $this->Paginator->sort('Roles.name',__('Role Associated')) ?></th>
                <th><?php echo $this->Paginator->sort('status',__('status')) ?></th>
                <th class="actions"><?php echo __('action') ?></th>
            </tr>

让我知道你有任何解决方案.

你只需要使用这个:
$this->paginate = [
    'sortWhitelist'=>['Roles.name']
];

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读