CDbCriteria params and array

I have the following code, which does not work.




$crit = new CDbCriteria(array(

  "condition" => "status='open' AND published='1' AND tag IN (:tags)",

  "order" => "publishdate DESC",

  "limit" => SAGD::INDEX_MAX_NEWS,

  'params' => array(':tags'=>SAGD::$ARTICLE_SET1),

));



SAGD::$ARTICLE_SET1 is an array of integer values for example, SAGD::$ARTICLE_SET1 = array(1,3,6);

Is it possible to pass an array like that for SQL IN(), and what is the correct method for doing so?

I ended up just manually building the "condition" like so




$IN = 'tags IN (....etc)';

$crit = new CDbCriteria(array(

  "condition" => "status='open' AND published='1' AND " . $IN,

  "order" => "publishdate DESC",

  "limit" => SAGD::INDEX_MAX_NEWS

))



… if there is a better way let me know.

I think you should pass implode(’,’, SAGD::$ARTICLE_SET1), because :tags should be a string, and an array, converted to a string is the “Array”.

CDbCriteria has a function called addInCondition(), that’s probably a little more robust.