How do you make a request with multiple conditions using CDbCriteria?



  • Used this instruction to create a spatial breakdown http://rmcreative.ru/blog/post/postranichnaja-razbivka-v-yii

    My code is:

    // Постраничная выборка всех рекламных новостей
        $criteria=new CDbCriteria;
        $criteria->condition='is_reklama=:isRekl';
        $criteria->params=array(':isRekl'=>1);
        $count=Article::model()->count($criteria);
    
    $pagination=new CPagination($count);
    $pagination->pageSize=3;
    $pagination->applyLimit($criteria);
    
    $articles = Article::model()->findAll($criteria);
    

    I have a request made on a condition. is_reklama=:isRekl
    I need to add another condition to the sample. I decided to replace the method. findAll()findAllByAttributes()
    I just can't figure out how to do it. findAllByAttributes() modify several conditions of request using CDbCriteria? If not CDbCriteriathat's clear, just a parameter, transferring a set of keys and values. And for the propigation, it's the request. CDbCriteria♪ Thank you very much.



  • findAllByAttributes Not if CDBCriteria is used.
    Use it. http://www.yiiframework.com/doc/api/1.1/CDbCriteria#addCondition-detail ♪
    $criteria->params=array(':isRekl'=>1); You can complement the elements of the mass. Example of additional conditions:

    $criteria->addCondition('is_super_puper_relama > :is_super_puper_relama');
    $criteria->params['is_super_puper_relama'] = '1234';
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2