Social Icons


Monday, July 8, 2013

filter by concatenation of model fields in CGridView

I have user model with first_name and last_name . It will show as full name (first_name+last_name). Now i want to search in Cgridview.

class User extends CActiveRecord
        public $fullName;

in search

$criteria->addSearchCondition('concat(first_name, " ", last_name)', $this->fullName); 

in rules()
array('..., fullName', 'safe', 'on' => 'search'),

in model  created a function
 public function getFullName()
                return $this->first_name . ' ' . $this->last_name;

And last I've put it in my view:

<?php $this->widget('zii.widgets.grid.CGridView', array(
          'columns' => array(
                        'name' => 'full_name',
                        'value' => '$data->getFullName()',

No comments:

Post a Comment