Note that there are some explanatory texts on larger screens.

plurals
  1. POYii role based access, administering own posts
    primarykey
    data
    text
    <p>I googled, read tutorials, blogs and experimented a lot. So I am able to define role based access to controller actions. Everything works fine. What I want to ask is. How can I write a rule to display,edit and delete a user's own post?</p> <p>By default it displays all post. However we can put data provider criteria to display own post. But how can I controll the CRUD for that?? Kindly help me. My code is bellow.</p> <pre><code> public function accessRules() { return array( array('allow', // allow all users to perform 'index' and 'view' actions 'actions' =&gt; array('index', 'view'), 'users' =&gt; array('*'), ), array('allow', // allow authenticated user to perform 'create' and 'update' actions 'actions' =&gt; array('create', 'update'), 'expression' =&gt; 'Yii::app()-&gt;controller-&gt;HaveAccess()', //'users' =&gt; array('@'), ), array('allow', // allow admin user to perform 'admin' and 'delete' actions 'actions' =&gt; array('admin', 'delete'), 'expression' =&gt; 'Yii::app()-&gt;controller-&gt;HaveAccess()', ), array('deny', // deny all users 'users' =&gt; array('*'), ), ); } </code></pre> <p><strong>for the post display:</strong></p> <pre><code> public function actionIndex() { $dataProvider = new CActiveDataProvider('Advertisment'); if (!$this-&gt;IsAdmin()) { $dataProvider = new CActiveDataProvider('Advertisment', array( 'criteria' =&gt; array( 'condition' =&gt; 'added_by='.$this-&gt;userId, 'order' =&gt; 'id DESC', ), 'pagination' =&gt; array( 'pageSize' =&gt; 20, ), )); } $this-&gt;render('index', array( 'dataProvider' =&gt; $dataProvider, )); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload