2017-01-05 84 views
0

我目前使用Codeigniter 3.1.2和Ion Auth。我可以登錄並查看我的儀表板頁面,但是如果我嘗試查看另一個需要用戶登錄的頁面,例如客戶頁面,我總是被重定向到登錄頁面。Ion Auth + Codeigniter logged_in總是重定向到登錄

控制器

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

回答

0
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'); 
} 

「!$這個 - > ion_auth-> LOGGED_IN()」 使用此構造之外,因爲它會每次運行。你應該創建一個不同的方法來每次在方法中調用。請勿將其用於索引