multiply search conditions

Hi, I have a beginner question about multiply search conditions. I need to do something like:

select … where( condition1 AND( condition2 OR condition3 or condition4 ) );

we can say, that condition5 = condition2 or condition3 or condition4;

so its all about: select… where( condition1 AND condition5 );

How should I do it along with yii filosophy? In symfony criteria we had criterion objects for such operations.

thanks in advance :rolleyes:

In Yii you have CDbCriteria - http://www.yiiframework.com/doc/api/CDbCriteria

iknow, that we have CDbCriteria. i was trying to solve my problems in many ways, e.g using addSearchCondition. but did you read my question? How can I prepare one composite condition chained with OR and add it into the main condition with AND?

in the simplest form you can use





$cr=new CDbCriteria();

$cr->condition= '( condition1 AND( condition2 OR condition3 or condition4 ) )';




thanks. And can we use addSearchCondition for instance? If yes, how to do it?

condition1-4 are the type of sql %name% LIKE ones, so I thought using addSearchCondition is the best way. If not, which one is?

This is my third project in Yii, and this time I want to use only its best features, and write the code as much as possible along with the framework philosophy.

again, thanks for ur time, Jan

I don’t know what you þink by “best way”…

For elegant written code there are the addCondition/addSearchCondition

Iif you check the source you will see that addSearchCondition call addCondition, and addCondition sets the condition property… so for the speed (a micromilisecond :) ) just set the condition property…

I realy don’t know how to get your need with addSearchCondition in other way than




$cr=new CDbCriteria();

$cr->addSearchCondition('condition1'...);

$cr->addSearchCondition('condition2 or condition3 or condition4',...);



Are these both two equal?




$cr=new CDbCriteria();

$cr->addSearchCondition('condition1'...);

$cr->addSearchCondition('condition2 or condition3 or condition4',...);






$cr=new CDbCriteria();

$cr->condition= '( condition1 AND( condition2 OR condition3 or condition4 ) )';



Obviously there is no AND in the first one. Can we do something like in the second example for addSearchCondition ?




$cr=new CDbCriteria();

$cr->addSearchCondition('condition1 AND ( condition3 or condition4 )',...);



Ops… addSearchCondition cannot be used that way, take a look at the doc - http://www.yiiframework.com/doc/api/CDbCriteria#addSearchCondition-detail

my example works with addCondition()

so if you use only one addCondition(‘big expresion’)… it’s the same as writing $cr->condition=‘big condition’

Thanks for your time. The rest I will figure out by myself :)