如何为查询创建cdbcriteria,如:
select * from table_name where 'profile_type'='*'OR 'profile_type'=$usertype AND 'location'='*'OR 'location'=$country
答案 0 :(得分:1)
您可以直接传递条件如下。
注意:这是方法之一。不是最终的解决方案。
$criteria = new CDbCriteria;
$criteria->condition = "(profile_type ='*' OR profile_type = $usertype) AND (location ='*' OR location = $country)";
$model = Model_name::model()->findAll($criteria );
答案 1 :(得分:1)
$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 );