Hey Guys,
I have an CGridView which displays some fields like name, surname and so on. It also displays phone numbers which is another table related as HAS_MANY.
In my people model I have declared the relation:
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'phones'=>array(self::HAS_MANY, 'AdPhone', 'person_id'),
);
}
where person_id is the index field in my ad_phone table
then I added a getter to recieve all phone numbers:
public function getAllPhoneNumbers()
{
// more than one phone exists for the user
if(sizeof($this->phones) > 1)
{
foreach($this->phones as $phone)
{
echo $phone->number."<br>";
}
}
else
{
foreach($this->phones as $phone)
{
return $phone->number;
}
}
}
and I also added the column to my gridview:
array('name'=>'allPhoneNumbers', 'header'=>'Phone', 'type'=>'raw', 'value'=>'$data->getAllPhoneNumbers()'),
But I have no idea how to make this field searchable like the others, the numbers are displayed properly just searching is not working with it. Could anyone assist me with this please? Thanks in advance!
-Seb