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.


Sorry by mistake i have post this question in the wrong area. i created a new under Yii 1 discussions.