我是一個絕對的網頁開發初學者。我現在正在使用CodeIgniter框架。CodeIgniter 3.0.6重定向功能無法正常工作
https://www.youtube.com/watch?v=5Xjme7Mw3UM&list=PLillGF-RfqbZQw-pSO62ha_imR_848j_X&index=6
我一直在按照上述到目前爲止教程。在觀看第6部分時,我在下面的登錄功能中遇到了重定向功能的問題。 重定向函數應該加載到索引/ home,但實際上沒有。它轉到用戶/登錄,應用程序說所請求的頁面不存在。
有沒有人遇到過類似的問題?如果您有,請留下您的評論! 英語不是我的第一語言,所以如果這篇文章沒有意義,或者您需要更多信息,請讓我知道。 任何意見將不勝感激!提前致謝!
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');
}
}
}
什麼是你的目錄結構之前加入? – Arun
只檢查你設置你的配置base_url? – user4419336
您是否在base_url的末尾加入了'$ config ['base_url'] ='http:// localhost/project /';'當您添加/結尾的base url時,您不必在此處添加它'重定向('home/index');'在家之前 – user4419336