php - Ion Auth + Codeigniterlogged_in 始终重定向到登录

标签 php codeigniter ion-auth

我目前正在使用带有 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/

相关文章:

codeigniter - 如何使用 ci-merchant 库在您的网站上处理信用卡付款选项(无需重定向到 paypal)paypalexpressceckout

php - 如何在 ion auth codeigniter 中创建子组?

PHP PDO 返回 SELECT FOUND_ROWS() 不一致的结果

php - 对端 : mod_fcgid: error reading data from FastCGI server 重置连接

codeigniter - 从查询中获取结果以插入到其他使用事件记录中

php - Codeigniter 命令行错误 - PHP fatal error : Class 'CI_Controller' not found

php - 未记住具有 Ion AUTH 登录名的 CodeIgniter

php - Codeigniter Ion Auth 编辑用户表

php - PDO:多。行和列 - 如何循环数组?

php - 使用 MYSQL 进行 Mosquitto 身份验证