I need some guidance in the right direction.
I have two models, Submissions and Participant.
In Participant I define a custom field FullName which is a combination of FirstName and LastName
The Participant model:
private $FullName;
public function rules()
{
...
array('FullName, Username, ... ', 'safe', 'on'=>'search'),
...
}
public function getFullName()
{
return $this->FirstName." ".$this->LastName;
}
public function setFullName($value)
{
$this->FullName = $value;
}
In Submissions, I have a ParticipantID field that links Participant, and I want to display all submissions in a grid which has the FullName column, and which should be filterable.
The Submissions model:
private $FullName;
public function relations()
{
return array(
'participant' => array(self::BELONGS_TO, 'Participant', 'ParticipantID'),
);
}
public function search()
{
...
if (isset($_GET['Add']['FullName']))
$criteria->compare('participant.FirstName',$_GET['Add']['FullName'],true);
//$criteria->compare('participant.FirstName', $this->FullName);
...
}
public function getFullName()
{
if ($this->FullName === null && $this->participant !== null) {
$this->FullName = $this->participant->FullName;
}
return $this->FullName;
}
public function setFullName($value)
{
$this->FullName = $value;
}
and in the admin view file I have:
...
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
array(
'name'=>'BotanicalName',
'type'=>'raw',
'value'=>'$data->master->BotanicalName',
'filter'=>false,
),
array(
'name'=>'FullName',
'header'=>'Full Name',
'type'=>'raw',
'value'=>'(isset($data->FullName))?$data->FullName:"Not Specified"',
),
...
If I have the following line in the search function of the admin view file, then the search does not work,
...
$criteria->compare('participant.FirstName', $this->FullName);
...
and I have tried various scenarios but can’t seem to get the filtering to work.