title: Yii - How to Hide/View Button in CGridview Based on User's Level?
body: <p>I tried to view or show button (CButtonColumn) in CGridView, in my /views/file/admin.php:</p>
  
  <pre><code>....
  //getLevel()==1 means ADMIN, getLevel==2 means common users
  array(
          'class'=&gt;'bootstrap.widgets.TbButtonColumn',
              'template'=&gt;'{view}{update}{delete}', 'visible'=&gt; (Yii::app()-&gt;user-&gt;getLevel()==1),
              'deleteConfirmation'=&gt;"js: 'Are you want to delete '+$(this).parent().parent().children(':first-child').text()+ '?'",
  
    //I tried to modify with this code below, but there's nothing happens, 'view' button not
    //display when I access as common user (getLevel()==2)    
              'buttons'=&gt;array(
                  'view' =&gt; array(
                      'visible'=&gt; Yii::app()-&gt;user-&gt;getLevel()==2,
                  ),
  
              )
      ),
  ....
  </code></pre>
  
  <p>WebUser.php</p>
  
  <pre><code>&lt;?php
  class WebUser extends CWebUser{
  
  protected $_model;
  
  protected function loadUser()
  {
      if ( $this-&gt;_model === null ) {
              $this-&gt;_model = User::model()-&gt;findByPk($this-&gt;id);
      }
      return $this-&gt;_model;
  }
  
  function getLevel()
  {
      $user=$this-&gt;loadUser();
      if($user)
          return $user-&gt;id_level;
      return 100;
  }
  }
  ?&gt;
  </code></pre>
  
  <p>I tried to do that code, but there 'view' button not display, and there's no error when I load the page. Can anyone help me solve this problem? Thanks a lot.</p>