简体   繁体   中英

Create CDBcriteria in yii

如何为查询创建cdbcriteria,如:

select * from table_name where 'profile_type'='*'OR 'profile_type'=$usertype  AND 'location'='*'OR 'location'=$country

You can directly pass condition as below.

Note: This is one of the method. Not an ultimate solution.

$criteria = new CDbCriteria;
$criteria->condition  = "(profile_type ='*' OR profile_type = $usertype)  AND (location ='*' OR location = $country)";

$model = Model_name::model()->findAll($criteria );

you can try sth like this:

$criteria = new CDbCriteria;
$criteria->condition  = "(profile_type='*' OR profile_type=:prof ) AND 
                         (location='*' OR  location=:loc ) ";

$criteria->params = array(':prof' => $usertype, ':loc' => $country);

$model = MyModel::model()->findAll($criteria );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM