0

我有 2 个模型:项目和用户。在项目中:

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
4

2 回答 2

5

那是因为$model->users不是CActiveDataProvider:它是一个CActiveRecords数组

尝试使用CArrayDataProvider代替:

<?php $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'user-grid',
    'dataProvider'=> new CArrayDataProvider($model->users),
    [...] 
    ),
)); ?>
于 2013-06-18T11:01:41.087 回答
0

你可以在 cgridView 中根据 Projects 和 users 进行 Group 和显示结果
Try This Thread Grouping members

于 2013-06-18T11:46:47.297 回答