Solved, for me anyway…
Note: I am not an experienced PHP person and I am a newbie to yii as well so please forgive my lack of efficient or proper coding techniques in both.
Step 1) Add Virtual Attribute for model attributes in same model - I will get to related model sortable later when I have a chance and if it is possible.
In my model:
private $_full_name = NULL;
public function getfull_name()
if (!isset($this->first_name) && !isset($this->last_name) && !isset($this->salutation))
$this->_full_name = NULL;
$this->_full_name = $this->last_name;
if (isset($this->first_name) || isset($this->last_name) )
$this->_full_name .= ', ';
$this->_full_name .= $this->first_name;
$this->_full_name .= ' ' . $this->salutation;
Step 2) In my model rules
public function rules()
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
array('full_name', 'safe', 'on'=>'edit, post, search'),
Step 3) In my model attributes
public function attributeLabels()
Step 4) In my model search function
... other criteria
$criteria->compare('first_name',$this->_full_name, true, 'OR');
$criteria->compare('last_name',$this->_full_name, true, 'OR');
$criteria->compare('salutation',$this->_full_name, true, 'OR');
$sort = new CSort();
$sort->attributes = array(
'asc'=>'last_name ASC, first_name ASC, salutation ASC',
'desc'=>'last_name DESC, first_name DESC, salutation DESC',
'id', ... other fields....,
return new CActiveDataProvider(get_class($this), array(
Step 5) In my view/admin.php
Step 6) In my view/_search.php
I removed the first_name, last_name, and salutation entries as they are not needed
<?php echo $form->label($model,'first_name'); ?>
<?php echo $form->textField($model,'first_name',array('size'=>60,'maxlength'=>100)); ?>
These are the only changes I made I think - if I notice something else I will add to this.
Again, I am not that experienced (a couple weeks) so please take this with a grain of salt. Hope it helps.
A Newbie so sorry if this is not ok…
I am having a problem figuring out how to accomplish the sorting of the virtual attribute.
Currently I have the virtual attribute working as well with correct filtering; however, the CGridView has no link on the header for sorting.
I have been searching but no definitive answer so far. If you could pass on the how to I would be grateful.
note: I tried placing the noted ‘user’=>array(…), portion into the attributes but no dice…
Thanks in advance.