无法重定向到新页面 - CodeIgniter

时间:2014-09-16 19:15:52

标签: php codeigniter redirect view

我有一个可以使用的登录系统,但是在重定向功能上它给了我错误The requested URL "http://localhost/musiclear/index.php/welcome" cannot be found or is not available. Please check the spelling or try again later.

这是我使用它的地方(login.php):

    function validate_credentials() {

    $this->load->model('membership_model');
    $query = $this->membership_model->validate();

    if ($query) { // if users credentials validated
        $data = array('usernames' => $this->input->post('username'), 
        'is_logged_in' => true);

        $this->session->set_userdata($data); //set session data
        redirect('welcome', 'refresh'); //redirect to home page
    } else { //incorrect username or password
        $this->index();
    }
}

这是我指导它(welcome.php)的地方:

class Welcome extends CI_Controller {

public function index() {
    $this->home();
}

public function home() {
    $this->load->model('model_users');

    $data['title'] = 'MVC Cool Title'; // $title
    $data['page_header'] = 'Intro to MVC Design';
    $data['firstnames'] = $this->model_users->getFirstNames();
    // just stored the array of objects into $data['firstnames] it will be accessible in the views as $firstnames

    $data['users'] = $this->model_users->getUsers();

    $this->load->view('home_view', $data);
}
}

我认为路径有问题,或者链接到哪里但我不确定。这是我的目录设置:

file setup

有人可以告诉我什么是错的,以及如何将其链接到我的页面?非常感谢

1 个答案:

答案 0 :(得分:0)

您是否在应用程序文件夹中创建了.htaccess?

也许这适用于您的项目:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /musiclear/index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
    ErrorDocument 404 /musiclear/index.php
</IfModule>

欢迎你