[英]Ion Auth + Codeigniter logged_in always redirects to login
I am currently using Codeigniter 3.1.2 with Ion Auth.我目前正在使用带有 Ion Auth 的 Codeigniter 3.1.2。 I can login and view my dashboard page, however if I attempt to view another page that requires the user to be logged in, such as the customer page I am always redirected to the login page.我可以登录并查看我的仪表板页面,但是如果我尝试查看另一个需要用户登录的页面,例如客户页面,我总是被重定向到登录页面。
Controller控制器
public function __construct(){
parent::__construct();
$this->load->library('form_validation');
$this->load->library('session');
$this->load->helper('form');
$this->load->helper('url');
$this->load->model('CRUD');
if (!$this->ion_auth->logged_in()) {
redirect('User/index');
}
}
public function index(){
$this->load->helper('form');
$this->load->view('login');
}
public function dashboard(){
$this->load->view('dashboard');
}
public function customerPage(){
$data['customer'] = $this->CRUD->getCustomers();
$this->load->view('customer', $data);
}
public function materialPage(){
$data['material'] = $this->CRUD->getMaterials();
$this->load->view('material', $data);
}
Thanks, CHTRK谢谢,CHTRK
public function __construct(){
parent::__construct();
$this->load->library('form_validation');
$this->load->library('session');
$this->load->helper('form');
$this->load->helper('url');
$this->load->model('CRUD');
if (!$this->ion_auth->logged_in()) {
redirect('User/index');
}
"!$this->ion_auth->logged_in()" use this outside the constructor because it will run every time. "!$this->ion_auth->logged_in()" 在构造函数之外使用 this,因为它每次都会运行。 you should create a different method to call every time in the methods.您应该创建一个不同的方法来每次在方法中调用。 don't use it for index不要将它用于索引
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.