为什么重定向在这里不起作用。我正在调用未定义的函数 redirect()。
class Login extends CI_Controller {
function index() {
parent::__construct();
$this->load->helper('form');
$this->load->helper('url');
$this->load->view('login_view');
}
function authenticate() {
$this->load->model('user_model');
$query = $this->user_model->authenticate();
if($query) {
$data = array(
'username' => $this->input->post('username'),
'is_logged_in' => true
);
$this->session->set_userdata($data);
redirect('/site/news_feed');
}
else {
$this->index();
}
}
}
最佳答案
将 authenticate()
方法上方的顶部部分更改为此...
class Login extends CI_Controller {
function __construct()
{
// this is your constructor
parent::__construct();
$this->load->helper('form');
$this->load->helper('url');
}
function index()
{
//this is only called when someone does not specify a method...
$this->load->view('login_view');
}
...
我强烈建议将这两个助手移动到自动加载,因为它们几乎是强制使用的......
关于php - Codeigniter 重定向不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7082795/