【问题标题】:Load a controller if authorized如果授权,加载控制器
【发布时间】:2017-02-24 22:37:24
【问题描述】:

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

    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.

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

【问题讨论】:

  • 您应该查看 HMVC 以在控制器中加载控制器,而普通 MVC 不能。
  • 我查看了维基。分层模型-视图-控制器可能是我在这里做的,不了解HMVC。我有一个用于登录的 MVC,以及用于应用程序不同部分的新 MVC。感谢@wolfgang1983 的评论,我一定会阅读更多。

标签: php codeigniter controllers


【解决方案1】:

如果用户有足够的凭据,我通常会加载控制器并检查其构造函数:

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。

【讨论】:

  • 这正是我想要的。现在正在工作...... Gracias@zJorge。
猜你喜欢
  • 2013-08-29
  • 1970-01-01
  • 2020-04-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-12
相关资源
最近更新 更多