Once I have tried to make it based on this wiki, unfortunately it was absolutely not working for me, I couldn’t figure out why. I’m not sure right now is it only for filtering one single corresponding field or any other fields.
I don’t really understand why is this not working like so:
I have:
- defined in model one of the related models’ attributes:
public $relatedAttribute;
- put into search() function the following:
$criteria->compare('relation.relatedAttribute',$this->relatedAttribute, true);
array('... relation.relatedAttribute', 'safe', 'on' => 'search'),
or
array('... relatedAttribute', 'safe', 'on' => 'search'),
no change in ‘not-working’ state.
it should work like so, shouldn’t it?
this is the only thing I haven’t put into my code:
return new CActiveDataProvider( 'Post', array(
'criteria'=>$criteria,
'sort'=>array(
'attributes'=>array(
'author_search'=>array(
'asc'=>'author.username',
'desc'=>'author.username DESC',
),
'*',
),
),
));
because I thought I don’t need this sorting capability. or do I have to put it there anyway?
once I could make it based on Hollyii’s Yii Blog article, but I can’t find right now which model it was…
I don’t know why, but there was even absolutely no textfield in the header of the grid, I thought I have to put there one:
array(
'name' => 'relation.relatedAttribute',
'header' => 'relatedAttribute',
'value' => '$data->relation->relatedAttribute',
'filter' => CHtml::textField('relatedAttribute'),
),
but still not working.
can the problem be that I’m using bootstrap? but I could make it once and it was also bootstrap…
now, if I do this:
array(
'name' => 'relatedAttribute', ...
),
the textfield appears on the top of the grid. but still no filtering.
it works!!!
array('... , relatedAttribute', 'safe', 'on' => 'search'),
it’s not allowed to put ‘relation.’ in front of variable in grid and in relations.