Codeigniter - 404 页面未找到

4
我正在使用Codeigniter。一切都很好,直到我创建了一个名为user_authentication.php的新控制器(位于http://localhost/etalasekursusci/index.php/user_authentication)。当我尝试打开此控制器时,浏览器显示“404页面未找到。您请求的页面不存在”。我的控制器文件在http://localhost/etalasekursusci/index.php/controllerhttp://localhost/etalasekursusci/index.php/user上运行良好,只有这一个失败了。 (顺便说一下,我从我的朋友那里复制了user_authentication.php文件。如果我将user类中的脚本复制到user_authentication类中,则可以访问user_authentication.php...) /application/.htaccess文件:
<IfModule authz_core_module>
    Require all denied
</IfModule>
<IfModule !authz_core_module>
    Deny from all
</IfModule>

/application/config/config.php 文件:

$config['base_url'] = 'http://localhost/etalasekursusci/';

/application/config/routes.php文件:

$route['default_controller'] = 'controller';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

/application/controllers/user.php 文件(可访问):

<?php
class user extends CI_Controller {
public function __construct()
{
    parent::__construct();

    $this->load->model('user_model');
}

public function index()
{
    $this->load->library('form_validation');

    $this->form_validation->set_error_delimiters('<div class="error">', '</div>');

    $this->form_validation->set_rules('nama', 'Nama Kursus', 'required|min_length[5]|max_length[20]');

    $this->form_validation->set_rules('alamat', 'Alamat Kursus', 'required|min_length[5]|max_length[40]');

    if ($this->form_validation->run() == FALSE)
    {
        $this->load->view('register_user');
    }
    else
    {
        $data = array(
        'lembaga' => $this->input->post('nama'),
        'alamat' => $this->input->post('alamat'),
        'paketkursus' => $this->input->post('paket'),
        'lokasi' => $this->input->post('lokasi'),
        'harga' => $this->input->post('biaya')
        );

        $this->user_model->insert_userinfo($data);

        $this->load->view('tambahberhasil');

    }
}
}

/application/controllers/user_authentication.php文件(无法访问):

<?php
class user_authentication extends CI_Controller {

public function __construct() {
parent::__construct();


$this->load->helper('form');


$this->load->library('form_validation');


$this->load->library('session');


$this->load->model('login_database');

}


public function user_login_show() {
$this->load->view('login_form');
}

public function user_registration_show() {
$this->load->view('registration_form');
}

public function new_user_registration() {

$this->form_validation->set_error_delimiters('<div class="error">', '</div>');

$this->form_validation->set_rules('name', 'Name', 'required|min_length[5]|max_length[20]');

$this->form_validation->set_rules('username', 'Username', 'required|min_length[5]|max_length[40]');

$this->form_validation->set_rules('email_value', 'Email', 'required|min_length[2]|max_length[50]');

$this->form_validation->set_rules('password', 'Password', 'required|min_length[6]|max_length[10]');

if ($this->form_validation->run() == FALSE) {
$this->load->view('registration_form');
} else {
$data = array(
'name' => $this->input->post('name'),
'user_name' => $this->input->post('username'),
'user_email' => $this->input->post('email_value'),
'user_password' => $this->input->post('password')
);
$result = $this->login_database->registration_insert($data) ;
if ($result == TRUE) {
$data['message_display'] = 'Registrasi Berhasil !';
$this->load->view('login_form', $data);
} else {
$data['message_display'] = 'Username yang ada inputkan sudah ada!';
$this->load->view('registration_form', $data);
}
}
}


public function user_login_process() {

$this->form_validation->set_error_delimiters('<div class="error">', '</div>');

$this->form_validation->set_rules('username', 'Username', 'required|min_length[5]|max_length[20]');

$this->form_validation->set_rules('password', 'Password', 'required|min_length[5]|max_length[40]');

if ($this->form_validation->run() == FALSE) {
$this->load->view('login_form');
} else {
$data = array(
'username' => $this->input->post('username'),
'password' => $this->input->post('password')
);
$result = $this->login_database->login($data);
if($result == TRUE){
$sess_array = array(
'username' => $this->input->post('username')
);

$this->session->set_userdata('logged_in', $sess_array);
$result = $this->login_database->read_user_information($sess_array);
if($result != false){
$data = array(
'name' =>$result[0]->name,
'username' =>$result[0]->user_name,
'email' =>$result[0]->user_email,
'password' =>$result[0]->user_password
);
$this->load->view('admin_page', $data);
}
}else{
$data = array(
'error_message' => 'Nama atau Password yang anda masukan salah !'
);
$this->load->view('login_form', $data);
}
}
}


public function logout() {

$sess_array = array(
'username' => ''
);
$this->session->unset_userdata('logged_in', $sess_array);
$data['message_display'] = 'Anda sudah Log Out !';
$this->load->view('login_form', $data);
}

}

有什么想法吗?

(顺便说一下,我从我的朋友那里复制了user_authentication.php文件。如果我将用户类中的脚本复制到用户认证类中,则可以访问user_authentication.php...)


1
看起来你需要配置你的路由,请查看CI文档(http://www.codeigniter.com/userguide2/general/routing.html)。 - Josef Engelfrost
1
请发布位于主文件夹etalasekursusci中的.htaccess文件,您正在使用哪个版本的CodeIgniter? - Kamran
你正在使用哪个版本的Codeigniter? - Ben Broadley
我的etalasekursusci主文件夹中没有.htaccess文件。我正在使用Codeigniter 3.0版本。 - Graha Pramudita
顺便说一句,如果我将用户类中的脚本复制到用户认证类中,那么就可以访问user_authentication.php文件了... - Graha Pramudita
显示剩余2条评论
2个回答

4
在Codeigniter 3中,你的类名必须以大写字母开头,并且文件名也应该如此。你应该尝试将user_authentication.php重命名为User_authentication.php,并更改开头的行:
<?php
class User_authentication extends CI_Controller {

同样地,user.php 应该改为 User.php,并将其开头的行改为:
<?php
class User extends CI_Controller {

这里可以找到解释这个类的文档:点击这里

3

2
基础URL不应该像这里的文档所述那样在末尾添加index.php:https://ellislab.com/codeigniter/user-guide/helpers/url_helper.html,它的目的是使您能够创建到静态资源(如图像或样式表)的链接。 - Ben Broadley

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接