I googled, read tutorials, blogs and experimented a lot. Therefore, I can determine role-based access to controller actions. Everything is working fine. I want to ask. How can I write a rule to display, edit and delete a user's own message?
By default, all messages are displayed. However, we can set the criteria for the data provider to display our own message. But how can I control CRUD for this? Please help me. My code is below.
public function accessRules() {
return array(
array('allow',
'actions' => array('index', 'view'),
'users' => array('*'),
),
array('allow',
'actions' => array('create', 'update'),
'expression' => 'Yii::app()->controller->HaveAccess()',
),
array('allow',
'actions' => array('admin', 'delete'),
'expression' => 'Yii::app()->controller->HaveAccess()',
),
array('deny',
'users' => array('*'),
),
);
}
to display messages:
public function actionIndex() {
$dataProvider = new CActiveDataProvider('Advertisment');
if (!$this->IsAdmin()) {
$dataProvider = new CActiveDataProvider('Advertisment', array(
'criteria' => array(
'condition' => 'added_by='.$this->userId,
'order' => 'id DESC',
),
'pagination' => array(
'pageSize' => 20,
),
));
}
$this->render('index', array(
'dataProvider' => $dataProvider,
));
}