For Yii Framework findAllByAttributes():
Obj::model()->findAllByAttributes($filterArr, $conditionArr);
$filterArr: To generate the SQL conditions in WHERE clause.
e.g., array('filter1'=>'v1', 'filter2'=>'v2'...)
$conditionArr: To generate the SQL other conditions (order by, limit...)
e.g., array('order'=>'v1 DESC', 'limit'=>'10',...)
e.g., if our SQL is:
SELECT id FROM user WHERE username = 'jack' ORDER BY creationdate
The following code may achieve this:
$filterArr = array('username'=>'jack');
$conditionArr = array('order'=>'creationdate');
User::model()->findAllByAttributes($filterArr, $conditionArr);
daxue.menggy.com
How to get only id from this syntax.
ReplyDelete$filterArr = array('username'=>'jack');
$conditionArr = array('order'=>'creationdate');
User::model()->findAllByAttributes($filterArr, $conditionArr);
sorry, you can't. you'd better to use CDbCriteria : http://www.larryullman.com/2013/07/24/using-cdbcriteria-in-the-yii-framework/
DeleteSuperb, fantastically helpful, many thanks.
ReplyDeletemy pleasure!
Delete