如果授权加载控制器

Load a controller if authorized

如果会话正常,我正在尝试加载控制器(仪表板)。

    if ($this->form_validation->run() == FALSE) {
     if(isset($this->session->userdata['logged_in'])){
    echo 'dashboard-01'; //test load
    $this->load->controllers('Dashboard');//Not sure if syntax is ok.

这可能吗?有没有更好的方法可以做到这一点?

我通常做的是加载控制器并检查其构造函数是否用户有足够的凭据:

class Sociedades extends CI_Controller {

    var $globales = array();

    function __construct()
    {
        parent::__construct();
        $this->load->database();
        $this->load->library(array('ion_auth','form_validation'));
        // Elliot, if you see this, don't delete it!
        $this->load->model('fSociety_model');

        if (!$this->ion_auth->logged_in())
        {
            //redirect them to the login page if not authorized
            redirect('auth/login', 'refresh');
        }
    }

    // then the index and other methods...
}

顺便说一下,我正在使用 Ben Edmund 的 IonAuth。