2017-03-02 18 views
0

私はpaginate関数の条件としてIDの配列を使用したいが、このエラーは '値を整数に変換できない'ということになる。しかし、どのように条件を配列のすべての値を探すようにすることができますか?ページング条件で配列を使用する[CakePHP 3]

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

http://stackoverflow.com/questions/26887511/how-to-create-a-in-clause-in-cakephp-query – ndm

+2

が重複する可能性を[CakePHPクエリで\ IN節を作成する方法は?](http://stackoverflow.com/questions/26887511/how-to-create-a-in-clause-in-cakephp-query) – ahoffner

答えて

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']); 
関連する問題