adding both equal and not equal conditions in Yii

user3894236 picture user3894236 · Aug 27, 2014 · Viewed 9.2k times · Source
$id = Yii::app()->user->getState("logId");
$name = Yii::app()->user->getState("username"); 

$dataProvider=Disnotification::model->findAllByAttributes(array('logID' => $id,'username'!=$name));

How can I find records which equals to $id but not equals to $name?

Answer

Developerium picture Developerium · Aug 27, 2014
$criteria = new CDbCriteria();
$criteria->compare('logID' , $id);
$criteria->addCondition('username != :username');
$criteria->params[ ':username' ] = $name;

$dataProvider = Disnotification::model()->findAll( $criteria );