Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如果授权,加载控制器_Php_Codeigniter_Controllers - Fatal编程技术网

Php 如果授权,加载控制器

Php 如果授权,加载控制器,php,codeigniter,controllers,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

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

    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。

您应该查看HMVC,以加载具有普通MVC无法加载的控制器的控制器。我在wiki上查看了一下。层次模型-视图-控制器可能就是我在这里所做的,而不了解HMVC。我有一个用于登录的MVC,以及用于应用程序不同部分的新MVC。感谢@wolfgang1983的评论,我一定会读到更多关于它的内容。这正是我想要的。现在正在工作。。。Gracias@zJorge.