title: Yii RBAC make Users update profile by himself
body: <p>I'm trying to do this with <a href="http://www.yiiframework.com/extension/mongodbauthmanager" rel="nofollow noreferrer">mongodbauthmanager</a>. I'm  follow step by step in <code>Usage</code> section but finally i'm getting <strong>PHP warning: Illegal offset type</strong>. I had posted this question at <a href="http://www.yiiframework.com/extension/mongodbauthmanager/#c12707" rel="nofollow noreferrer">Yii Extension</a> before clone to SO:</p>
  <p>Please tell me what is wrong?</p>
  <p><strong>1// Config</strong></p>
  <pre><code> 'authManager'=&gt;array(
      'class'         =&gt;'CMongoDbAuthManager',
      'showErrors'    =&gt; true,
    ),
  </code></pre>
  <p><strong>2// Create auth items in db</strong></p>
  <pre><code>$auth = new CMongoDbAuthManager();
  
  $bizRule = 'return Yii::app()-&gt;user-&gt;id==$params[&quot;User&quot;]-&gt;_id;';
  $auth-&gt;createTask('updateSelf', 'update own information', $bizRule);
  //I had tried with $auth-&gt;createOperation() but they has the same error
  $role = $auth-&gt;createRole('user');
  $role-&gt;addChild('updateSelf');
  
  $auth-&gt;save();
  </code></pre>
  <p>and here is result in db
  <a href="http://i.minus.com/iIpXoBlDxaEfo.png" rel="nofollow noreferrer">result in db http://i.minus.com/iIpXoBlDxaEfo.png</a></p>
  <p>**3// Checking access in controller ** - <em>UPDATE CODE AND ERROR</em></p>
  <pre><code>public function actionUpdate($id)
      {
          $model=$this-&gt;loadModel($id);
          $params = array('User'=&gt;$model);
          if (!Yii::app()-&gt;user-&gt;checkAccess('updateSelf', Yii::app()-&gt;user-&gt;id,$params) )
          {
              throw new CHttpException(403, 'You are not authorized to perform this action');
          }
  //another statement ...
  }
  </code></pre>
  <p><strong>4// Getting error:</strong></p>
  <p><strong>Fatal error</strong> : Cannot use object of type MongoId as array in F:\Data\03. Lab\www\yii\framework\web\auth\CAuthManager.php(150) : <strong>eval()'d</strong> code on line 1</p>
  <h1>RESOLVED PROBLEM</h1>
  <p>Base-on the answer of <code>@Willem Renzema</code>, I resolve my problem. Now, I update here and hope it useful for someone have this error.</p>
  <p><strong>0// First, config authManager with defaultRoles</strong></p>
  <pre><code>   'authManager'=&gt;array(
          'class'=&gt;'CMongoDbAuthManager',
          'showErrors' =&gt; true,
          'defaultRoles'=&gt; array('user'),//important, this line help we don't need assign role for every user manually
      ),
  </code></pre>
  <p><strong>1// Fix save id in UserIdentity class</strong></p>
  <pre><code>class UserIdentity extends CUserIdentity
  {
      private $_id;
      //...
      public function authenticate()
      {
           //...
           $this-&gt;_id = (string)$user-&gt;_id;//force $this save _id by string, not MongoId object
           //...
      }
      //...
  }
  </code></pre>
  <p><strong>2// Fix $bizrule in authe items</strong>
  ($bizrule will run by <code>eval()</code> in <code>checkAccess</code>)</p>
  <pre><code>//use _id as string, not MongoId object
  $bizRule = 'return Yii::app()-&gt;user-&gt;id==(string)$params[&quot;User&quot;]-&gt;_id;';
  </code></pre>
  <p><strong>3// And user checkAccess to authorization</strong></p>
  <pre><code>public function actionUpdate($id){
          /**
           * @var User $model
           */
          $model=$this-&gt;loadModel($id);
          $params = array('User'=&gt;$model);
          if (!Yii::app()-&gt;user-&gt;checkAccess('updateSelf', $params) )
          {
              throw new CHttpException(403, 'You are not authorized to perform this action');
          }
          //...
  }
  </code></pre>
  <p>4// Done, now we can use checkAccess :D</p>