我刚安装了Codeigniter HMVC,我非常喜欢它的工作方式,但我是新手。我的问题是我如何检查登录?我知道我必须制作一个登录模块。然后我进入核心文件夹并将其添加到MX_Loader
function __construct(){
$this->load->helper('url');
redirecht('login');
}
但它没有识别助手命令。难道我做错了什么?我想查看此页面上的会话,如果会话不存在,我想将其重定向到登录模块。我该怎么做?
提前致谢
答案 0 :(得分:0)
为此你必须包含/自动加载会话库。
尝试以下示例..
打开“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');
}
}
希望这会有所帮助。