findByAttributes example

Is it possibly to test the same attribute for multiple values?


Class::model()->findByAttributes(array('type' => array('foo', 'bar'));

I think this is possible that way in Yii 2. In Yii 1 use:


$criteria=new CDbCriteria();

$criteria->addInCondition('type',array('foo', 'bar'));

Class::model()->findAll($criteria);

Thanks Bizley!




Person::model()->findByAttributes(array('first_name'=>$firstName,'last_name'=>$lastName));



Is this paramaterized?

Does querying without a CDbCriteria object leave you vulnerable to SQL injection?

Yes it is.

Not necessarily, you can always bind parameters into plain SQL prepared statements manually. But even using CActiveRecord and CDbCriteria can’t guarantee protection in all possible use cases (or, more precisely, the protection can be easily bypassed by improper usage). When in doubt, check the code of CActiveRecord/CDbCriteria.

gotcha. Thanks!