Addcolumncondition Method With Like Instead Of = (Equal)

Hi there,

I have a need like this using addColumnCondition()

foreach($query_set as $query){

    foreach($attributes as $attribute=>$v){

        $attributes[$attribute] = $query;


    $criteria->addColumnCondition($attributes, 'OR', 'AND');


this generates,

(attr1=:ycp0 OR attr2=:ycp1) AND (attr1=:ycp2 OR attr2=:ycp3)

but i need it be with LIKE instead of equal condition.


 (attr1 LIKE %:ycp0% OR attr2 LIKE %:ycp1%) AND (attr1 LIKE %:ycp2% OR attr2 LIKE %:ycp3%)

I found according to yii’s default behavior this is not allowed yet. can i know if there is another way to get this done ?

my solution was as below,

class AppCriteria extends CDbCriteria {

   public function addColumnCondition($columns, $columnOperator = 'AND', $operator = 'AND', $like = true) {

      $params = array();

      foreach ($columns as $name=>$value) {

        if ($value === null)

            $params[] = $name.' IS NULL';

        else {

            if ($like)

           	$params[] = $name.' LIKE %'.self::PARAM_PREFIX.self::$paramCount.'%';


           	$params[] = $name.'='.self::PARAM_PREFIX.self::$paramCount;

            $this->params[self::PARAM_PREFIX.self::$paramCount++] = $value;



      return $this->addCondition(implode(" $columnOperator ", $params), $operator);




i am just wondering why this is not provided by yii still. let me know if this can be achieved in a different way.


$values = array('foo','bar');

$attributes = array('attr1','attr2');

$criteria = new CDbCriteria();

foreach($values as $value) {

    $tempCriteria = new CDbCriteria();

    foreach ($attributes as $attribute) {






echo $criteria->condition."\n";



((attr1 LIKE :ycp0) OR (attr2 LIKE :ycp1)) AND ((attr1 LIKE :ycp2) OR (attr2 LIKE :ycp3))



    [:ycp0] => %foo%

    [:ycp1] => %foo%

    [:ycp2] => %bar%

    [:ycp3] => %bar%


Thanks. but I think we should incorporate the last param[size="2"], [/size][size="2"]$like [/size][color="#666600"][size="2"]=[/size][/color] [color="#000088"][size="2"]true [/size][/color]to [size="2"]addColumnCondition in a upcoming yii version. [/size]