title: How to assign role and checkaccess method in yii?
body: <p>I am new in yii for Role Management, <br>
  I have 2 Role like Admin1,Admin2<br>
  I have 2 controllers and it's action like <br><br>
  (1)UserController - create,update,delete <br>
  (2)CategoryController - view,create,update <br></p>
  
  <p>I want to give checkaccess method for Admin1 like <br>
  (1)UserController - update,delete <br>
  (2)CategoryController - update <br></p>
  
  <p>I want to give checkaccess method for Admin2 like <br>
  (1)UserController - create,update,delete<br>
  (2)CategoryController - create,view <br></p>
  
  <p>How can i give checkpermission for this 2 controller for particular admin ?
  Any help will be really appreciated.</p>
  
  <p>Here is my checkaccess method but it gives me error</p>
  
  <pre><code>class UserIdentity extends CUserIdentity
  {
      private $_id;
          public $role;
          public $roleName;
  
      /**
       * Authenticates a user.
       * @return boolean whether authentication succeeds.
       */
      public function authenticate()
      {
          $username = $this-&gt;username;
          $password = md5($this-&gt;password);
          $user=Login_User::model()-&gt;findByAttributes(array('Email'=&gt;$username,'Password'=&gt;$password,'Status'=&gt;'1'));
          if(empty($user))
          {
              $this-&gt;errorCode=self::ERROR_USERNAME_INVALID;
          }
          elseif($password != $user-&gt;Password)
          {
              $this-&gt;errorCode=self::ERROR_PASSWORD_INVALID;
          }
          else
          {
              $this-&gt;_id=$user-&gt;UserID;
              $this-&gt;username=$user-&gt;Email;
                          $this-&gt;role=$user-&gt;RoleID;
  
                          $roleQuery = "SELECT * FROM role WHERE RoleID = ".$user-&gt;RoleID." ";
                          $roleData = Yii::app()-&gt;db-&gt;createCommand($roleQuery)-&gt;queryAll();
  
                          if(isset($roleData[0]['Title']) &amp;&amp; $roleData[0]['Title'] != '') {
                              $this-&gt;roleName = $roleData[0]['Title'];
                          }  
  
                          if($user-&gt;RoleID != '') {
                              $query = "SELECT * FROM rolepermission WHERE RoleID = ".$user-&gt;RoleID." AND Status = 1 ";
                              $permissionData = Yii::app()-&gt;db-&gt;createCommand($query)-&gt;queryAll();
                          }
  
                          $auth=Yii::app()-&gt;authManager;
                          $rolePemirssion=$auth-&gt;createRole($this-&gt;roleName);
                          foreach($permissionData as $key =&gt; $value) {
                              $rolePemirssion-&gt;addChild($value['Controller'].$value['Action']);
                          }
              $this-&gt;errorCode=self::ERROR_NONE;
          }
          return $this-&gt;errorCode==self::ERROR_NONE;
      }
  
  }
  </code></pre>