密码点火器登录系统HMVC


Codeigniter login system HMVC

我刚刚安装了Codeigniter HMVC,我真的很喜欢它的工作方式,但我是新手。我的问题是如何检查登录?我知道我必须制作一个登录模块。然后我进入核心文件夹,将其添加到MX_Loader 中

function __construct(){
    $this->load->helper('url');
    redirecht('login');
} 

但它无法识别helper命令。我做错什么了吗?我想检查这个页面上的会话,如果会话不存在,我想将其重定向到登录模块。我该怎么做?

提前感谢

为此,您必须包含/自动加载会话库。

请尝试以下示例。。

打开"application/config/autoload.php文件并设置以下.

$autoload['libraries'] = array('session');
$autoload['helpers'] = array('url');

在登录控制器中(验证数据库中是否存在用户帐户),完成数据库验证后,添加以下行

$session_array = array('admin_id' => "1",'username' => "admin"); // here the "1" and the string "admin" are just for example. modify the array key and value as per your requirement. 
$this->session->set_userdata('user_logged_in', $session_array);
 redirect('admin/dashboard', 'refresh');

通过此行,会话将被添加到应用程序中。为了进行评估,请在函数__construct中添加以下行。

function __construct() {
    parent::__construct();
    if(!$this->session->userdata('user_logged_in')){
     redirect('login');
    }   
}

希望这会有所帮助。