title: codeigniter HMVC: Check user permissions for individual functions in controller
body: <p>I am working with HMVC module extension for codeigniter. Read this wonderful article - <a href="https://web.archive.org/web/20130811102028/http://jondavidjohn.com/blog/2011/01/scalable-login-system-for-codeigniter-ion_auth" rel="nofollow">Scalable Login System for CodeIgniter – Ion_Auth</a>. 
  What this article suggests is that we can create multiple custom controllers and based on the logged in user's role, redirect the user to his respective controllers. 
  For example, for Admin redirect him to a controller that extends Admin_Controller and so on:</p>
  
  <pre><code>class Admin_Controller extends CI_Controller {
  
      public function __construct() {
  
          parent::__construct();
  
          if( ! $this-&gt;ion_auth-&gt;is_admin()) {
              redirect('/');
          }
      }
  }
  </code></pre>
  
  <p>So, we can apply common rules at the Base controller level itself for all the methods/views within that controller. That is where I have a query: What if i don't want to have global control for all the views within that controller.</p>
  
  <p>Or put in other words - if I need to have specific control for individual views, how to go about it. For example - I have a controller named 'Blog' and methods named - 'view', 'add', 'edit'. Now, view is applicable to all kinds of users, while only Admin should be able to add or edit a blog. Which means I cannot put controller level logic..</p>
  
  <pre><code>class Blog_Controller extends Admin_Controller {
      // should be accessible to both Admin and non-logged in user
      public function view() {..} 
  
      // Following are only accessible to Admin
      public function edit() {..}
      public function create() {...}
  }
  </code></pre>
  
  <p>One way i can think of is to duplicate code in multiple controllers and handle views specific to the user role.</p>