Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Create a file called <code>MY_controller.php</code> (the prefix can be edited in config file) in <code>/application/core</code>:</p> <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class MY_Controller extends CI_Controller { function __construct() { parent::__construct(); //Initialization code that affects all controllers } } class Public_Controller extends MY_Controller { function __construct() { parent::__construct(); //Initialization code that affects Public controllers. Probably not much needed because everyone can access public. } } class Admin_Controller extends MY_Controller { function __construct() { parent::__construct(); //Initialization code that affects Admin controllers I.E. redirect and die if not logged in or not an admin } } class Member_Controller extends MY_Controller { function __construct() { parent::__construct(); //Initialization code that affects Member controllers. I.E. redirect and die if not logged in } } </code></pre> <p>Then anytime you create a new controller, you decide what access it requires</p> <pre><code> class Book extends Member_Controller { //Code that will be executed, no need to check anywhere if the user is logged in. //The user is guaranteed to be logged in if we are executing code here. //If you define a __construct() here, remember to call parent::__construct(); } </code></pre> <p>This cuts code duplication a lot, since if you need another member controller other than <code>Book</code> you can just extend the <code>Member_Controller</code>. Instead of having to do the checks in all of them.</p>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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