Saturday, 31 March 2012

YII Framework model findAllByAttributes()

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);


帮自己宣传一下刚上线的网站 梦奇网;目前的提供的服务是 签证搜索 和 时间和日期。谢谢大家支持,SEO下!

4 comments:

  1. How to get only id from this syntax.

    $filterArr = array('username'=>'jack');
    $conditionArr = array('order'=>'creationdate');
    User::model()->findAllByAttributes($filterArr, $conditionArr);


    ReplyDelete
    Replies
    1. sorry, you can't. you'd better to use CDbCriteria : http://www.larryullman.com/2013/07/24/using-cdbcriteria-in-the-yii-framework/

      Delete
  2. Superb, fantastically helpful, many thanks.

    ReplyDelete