Q : 如何在用户网格视图中显示用户的角色?
描述:我正在使用用户和权限扩展。我想在用户/管理员的网格视图中显示用户的角色。并按用户角色过滤。我怎样才能?
这是我的看法
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'user-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
array(
'name' => 'username',
'type'=>'raw',
'value' => 'CHtml::link(UHtml::markSearch($data,"username"),array("admin/view","id"=>$data->id))',
),
array(
'name'=>'email',
'type'=>'raw',
'value'=>'CHtml::link(UHtml::markSearch($data,"email"), "mailto:".$data->email)',
),
'create_at',
'lastvisit_at',
array(
'name'=>'status',
'value'=>'User::itemAlias("UserStatus",$data->status)',
'filter' => User::itemAlias("UserStatus"),
),
array(
'class'=>'CButtonColumn',
),
),
));
这是我的控制器
public function actionIndex()
{
$rasdataProvider = new RAssignmentDataProvider();
$dataProvider=new CActiveDataProvider('User', array(
'criteria'=>array(
'condition'=>'status>'.User::STATUS_BANNED,
),
'pagination'=>array(
'pageSize'=>Yii::app()->controller->module->user_page_size,
),
));
$this->render('index',array(
'dataProvider'=>$dataProvider,
'rasdataProvider'=>$rasdataProvider,
));
}
更新#1
这是 user.php 的关系
public function relations()
{
$relations = Yii::app()->getModule('user')->relations;
if (!isset($relations['profile']))
$relations['profile'] = array(self::HAS_ONE, 'Profile', 'user_id');
return $relations;
}