【问题标题】:Use array in pagination conditions [CakePHP 3]在分页条件下使用数组 [CakePHP 3]
【发布时间】:2017-03-03 08:37:53
【问题描述】:

我想使用一个 id 数组作为我的分页函数的条件,但我收到此错误“无法将值转换为整数”,我知道数组不是整数,但我怎样才能使条件看起来对于数组中的所有值。

$friendsid = explode(',', $this->Auth->user('friends'));
$this->paginate = [ 
    'conditions' => [
        'Users.id' => $friendsid,
    ]
]; 
$this->set('users', $this->paginate($this->Users));
$this->set('_serialize', ['users']);

【问题讨论】:

标签: php arrays cakephp pagination cakephp-3.0


【解决方案1】:

你可以试试:

$friendsid = explode(',', $this->Auth->user('friends'));
$query     = $this->Users->find() 
                ->where(function ($exp, $q) use ($friendsid) {
                    return $exp->in('Users.id', $friendsid);
                });
$this->set('users', $this->paginate($query));
$this->set('_serialize', ['users']);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-26
    • 1970-01-01
    • 2011-09-27
    • 1970-01-01
    • 2020-06-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多