我目前正在使用带有 Ion Auth 的 Codeigniter 3.1.2。我可以登录并查看我的仪表板页面,但是,如果我尝试查看需要用户登录的另一个页面(例如客户页面),我总是会重定向到登录页面。
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);
}
谢谢, 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()"在构造函数之外使用它,因为它每次都会运行。您应该创建一个不同的方法来每次在方法中调用。不要将其用于索引
关于php - Ion Auth + Codeigniterlogged_in 始终重定向到登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41494557/