Reputation: 7777
I need to use where clause on yii
, below of my code, I need to add where activated == 0 && send_email == 0
.
$model = User::model()->findAll();
Thanks
Upvotes: 2
Views: 1052
Reputation: 1991
There are multiple ways to do this:
$model = User::model()->findAll('activated=0 AND send_email=0');
Or,
$model = User::model()->findAll('activated=:activated And send_email=:sendEmail',
array(':activated'=>0,':sendEmail'=> 0));
Or,
$criteria = new CDbCriteria;
$criteria->condition='activated=:activated AND send_email=:sendEmail';
$criteria->params=array(':activated'=>0,':sendEmail'=>0);
$model=User::model()->findAll($criteria);
Or,
$model = User::model()->findAllByAttributes(array('activated'=>0, 'send_email'=>0));
Or,
$model = User::model()->findAllBySql('SELECT * FROM user WHERE activated=:activated AND send_email=:sendEmail', array(':activated'=>0, 'sendEmail'=>0));
More info here. Hope that helps :)
Upvotes: 2
Reputation: 8033
Simply try this:
$model = User::model()->findAll(array("condition"=> "activated=0 AND send_email=0"));
Upvotes: 1