CodeIgniter 3.0.6 重定向功能无法正常工作
CodeIgniter 3.0.6 Redirect function does not work correctly
我绝对是网络开发的初学者。我现在正在使用 CodeIgniter 框架。
https://www.youtube.com/watch?v=5Xjme7Mw3UM&list=PLillGF-RfqbZQw-pSO62ha_imR_848j_X&index=6
到目前为止,我一直在按照上面的教程进行操作。观看第 6 部分时,我在下面的登录功能中遇到重定向功能问题。
重定向函数应该加载到 index/home,但实际上并没有。它转到 user/login,应用程序说请求的页面不存在。
有没有人遇到过下面类似的问题?如果你有,请留下你的意见!
英语不是我的第一语言,所以如果这个 post 没有意义或者您需要更多信息,也请告诉我。
任何意见,将不胜感激!提前致谢!
User.php
public function login(){
$this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]');
$this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[50]');
if($this->form_validation->run() == FALSE){
// nothing
} else{
// get from post
$username = $this->input->post('username');
$password = $this->input->post('password');
// get user id from the model
$user_id = $this->User_model->login_user($username, $password);
// validate user
if($user_id){
// create array of user data
$user_data = array(
'user_id' => $user_id,
'username' => $username,
'logged_in' => true
);
// set session data
$this->session->set_userdata($user_data);
$this->session->set_flashdata('login_success', 'You are now logged in');
redirect('home/index');
}else{
// set error
$this->session->set_flashdata('login_failed', 'Sorry the login info that you entered is invalid');
redirect('home/index');
}
}
}
尝试在 url
前添加“/”
redirect('/home/index');
请检查您是否设置了配置 base_url?
或
尝试在 url
前添加“/”
redirect('/home');
我绝对是网络开发的初学者。我现在正在使用 CodeIgniter 框架。
https://www.youtube.com/watch?v=5Xjme7Mw3UM&list=PLillGF-RfqbZQw-pSO62ha_imR_848j_X&index=6
到目前为止,我一直在按照上面的教程进行操作。观看第 6 部分时,我在下面的登录功能中遇到重定向功能问题。 重定向函数应该加载到 index/home,但实际上并没有。它转到 user/login,应用程序说请求的页面不存在。
有没有人遇到过下面类似的问题?如果你有,请留下你的意见! 英语不是我的第一语言,所以如果这个 post 没有意义或者您需要更多信息,也请告诉我。 任何意见,将不胜感激!提前致谢!
User.php
public function login(){
$this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]');
$this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[50]');
if($this->form_validation->run() == FALSE){
// nothing
} else{
// get from post
$username = $this->input->post('username');
$password = $this->input->post('password');
// get user id from the model
$user_id = $this->User_model->login_user($username, $password);
// validate user
if($user_id){
// create array of user data
$user_data = array(
'user_id' => $user_id,
'username' => $username,
'logged_in' => true
);
// set session data
$this->session->set_userdata($user_data);
$this->session->set_flashdata('login_success', 'You are now logged in');
redirect('home/index');
}else{
// set error
$this->session->set_flashdata('login_failed', 'Sorry the login info that you entered is invalid');
redirect('home/index');
}
}
}
尝试在 url
前添加“/”redirect('/home/index');
请检查您是否设置了配置 base_url?
或
尝试在 url
前添加“/”redirect('/home');