Reputation: 1526
I'm trying to create a login function in Cake 1.3.10 that checks an extra condition apart from username and password. I'm using the $this->Auth->userScope for that.
If I check just one condition it works fine. I have this in my beforeFilter():
$this->Auth->userScope = array('User.status' => 1);
However, if I use and OR (like in the finds) it doesn't work:
$this->Auth->userScope = array('OR'=> array('User.status' => 1, 'User.status' => 2));
Doing that it ignores the first condition of the OR, just considering the second one.
Is there any way to acheive this with userScope?
Upvotes: 0
Views: 338
Reputation: 21743
Basic PHP. It does not ignore it, but due to the nature of arrays overwrites the first with the second. You may never use the same key in an array more than once.
So it's:
$this->Auth->userScope = array(
'OR' => array(array('User.status' => 1), array('User.status' => 2)))
Or in your case, since its CakePHP we are talking about, the cleaner solution (to merge them):
$this->Auth->userScope = array('User.status' => array(1, 2));
Which will be transformed in a simple "IN (1, 2)" statement.
Upvotes: 3