Hi all,
It’s been a couple days since I’m trying to make all my CGridView tables sortable but couldn’t get this one working.
So I have two models: Notes and Users. The relation is the following: Notes.UserId => User.Id
I’m using a CGridView to list all the Notes as follows:
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => new CArrayDataProvider($notes, array(
'pagination' => array(
'pagesize' => 10,
'route' => 'notes/AjaxNotesList',
'params' => $params,
),
'sort' => array(
'attributes' => array('user' => array(
'asc' => 'user.name',
'desc' => 'user.name DESC'
)
),
'defaultOrder' => 'id DESC',
'route' => 'notes/AjaxNotesList',
)
)),
'pager' => array(
'class'=>'CAjaxLinkPager',
'updateId' => 'notesListDiv',
'loadingCssClass' => 'grid-view-loading',
),
'id' => 'notesList',
'columns'=>$columns,
'summaryText'=> 'All review findings which are still open',
));
When I click on the user’s name column I get the following exception: ‘Property “Note.user.name” is not defined.’
Here’s my Note model class:
...
* The followings are the available model relations:
* @property User $user
*/
...
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(
'user' => array(self::BELONGS_TO, 'User', 'userId'),
);
}
So as you can see the User property should exist because it is defined in the model.
Do you guys have any suggestions? I went through the forum completely but couldn’t find any solution.