如果授权,请加载控制器

时间:2017-02-24 22:37:24

标签: php codeigniter controllers

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

    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.

这可能吗?对于如何做到这一点有更好的方法吗?

1 个答案:

答案 0 :(得分:2)

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

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。