el_pup_le
el_pup_le

Reputation: 12189

Codeigniter base controller

Is it a good design to have all controllers redirect to the site's base controller with a page identifier as the parameter, then having the base controller redirect based on some logic around that parameter?

//base controller

function __construct($fromPage, $toPage) {

    parent::__construct();

    if($toPage == 'member_only') {
       $this->is_logged_in();
    }

}

function is_logged_in($controller) {

   //redirect to appropriate controller from here?

}

Some suggestions on base controller practice would be splendid :)

Upvotes: 1

Views: 959

Answers (1)

Panagiotis Panagi
Panagiotis Panagi

Reputation: 10087

In general, it is better to build your controllers around your models.

If you have a User model, match it with a User controller. And route all requests related to the User model to the corresponding controller (User). Same with, for example, Article model <-> Article Controller, etc.

Edit: For checking if the user is logged in (or some other common functionality), consider MY_Controller

Upvotes: 4

Related Questions