How to use Yii Framework CGridView for Active Records with Relations

When use CGridView to display Active Records with relationship, we should notice some points For CGridView’s Columns properties, you should use ‘relation[property]’ as your columns name (e.g. user[nick]). Or this column name will be fillet by CDataColumn::renderFilterCellContent() defined in Yii/zii/widgets/grid/CDataColumn.phps . (refer code strpos($this->name,'.')==false conditions normally in line 94). use $data->relation->property as CGridView’s Column’s value property. such as value=>'$data->user->nick' Create your search condition into Model’s search method by visit $_GET variable....

November 20, 2013 · 1 min