代码点火器 3.0.6 重定向功能无法正常工作


CodeIgniter 3.0.6 Redirect function does not work correctly

我绝对是Web开发的初学者。我现在正在使用CodeIgniter框架。

https://www.youtube.com/watch?v=5Xjme7Mw3UM&list=PLillGF-RfqbZQw-pSO62ha_imR_848j_X&index=6

到目前为止,我一直在按照上面的教程进行操作。观看第 6 部分时,我在下面的登录功能中的重定向功能有问题。重定向函数应该加载到索引/主页,但实际上没有。它转到用户/登录,应用程序说请求的页面不存在。

有没有人遇到过类似的问题?如果您有,请留下您的意见!英语不是我的第一语言,所以如果这篇文章没有意义或者您需要更多信息,也请告诉我。任何建议将不胜感激!提前感谢!

用户.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');
        }
    }
}

尝试在网址前添加"/"

redirect('/home/index');

只是检查您是否设置了配置base_url?

尝试在网址前添加"/"

redirect('/home');