我有两个模型:项目和用户。在项目中:
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(
"users"=>array(self::MANY_MANY, 'User',
'projects_users(project_id, user_id)'),
);
}我想列出所有在实际项目中的用户,$model包含实际项目:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'user-grid',
'dataProvider'=>$model->users,
'columns'=>array(
'ID',
'username',
'displayname',
'firstname',
'lastname',
'email',
/*
'password',
'isAdmin',
*/
array(
'class'=>'CButtonColumn',
'template'=>'{delete}',
),
),
)); ?>不幸的是,我得到了一个错误:
Fatal error: Call to a member function getData() on a non-object in /var/www/vhosts/aevers.com/editor/framework/zii/widgets/CBaseListView.php on line 107发布于 2013-06-18 19:01:41
这是因为$ CActiveDataProvider ->users不是一个模型:它是一个数组 of CActiveRecords。
请尝试使用:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'user-grid',
'dataProvider'=> new CArrayDataProvider($model->users),
[...]
),
)); ?>发布于 2013-06-18 19:46:47
您可以在cgridView中根据项目和用户对结果进行分组和显示
尝试此线程Grouping members
https://stackoverflow.com/questions/17166587
复制相似问题