Reputation: 443
I want to use an array of ids as a condition to my paginate function, but I get this error 'Cannot convert value to integer', I understand that a array is not an integer, but how could I make the condition look for all the values in the array.
$friendsid = explode(',', $this->Auth->user('friends'));
$this->paginate = [
'conditions' => [
'Users.id' => $friendsid,
]
];
$this->set('users', $this->paginate($this->Users));
$this->set('_serialize', ['users']);
Upvotes: 0
Views: 803
Reputation: 1135
You could try it:
$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']);
Upvotes: 1