php – Codeigniter重定向无法正常工作
发布时间:2020-12-13 22:18:57 所属栏目:PHP教程 来源:网络整理
导读:为什么不重定向在这里工作.我正在调用未定义的函数redirect(). class Login extends CI_Controller { function index() { parent::__construct(); $this-load-helper('form'); $this-load-helper('url'); $this-load-view('login_view'); } function authent
|
为什么不重定向在这里工作.我正在调用未定义的函数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');
}
...
我强烈建议将这两个助手自动加载,因为他们几乎要求使用…… (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
