[英]Codeigniter - 404 Page Not Found
I'm using Codeigniter. 我正在使用Codeigniter。 Everything is fine until when I'm create new controller named user_authentication.php (located on http://localhost/etalasekursusci/index.php/user_authentication ).
一切都很好,直到我创建名为user_authentication.php的新控制器(位于http://localhost/etalasekursusci/index.php/user_authentication )。 When I try to open this controller, the browser said "404 Page Not Found. The page you requested was not found".
当我尝试打开此控制器时,浏览器会显示“找不到404页面。找不到您请求的页面”。 My controller files on http://localhost/etalasekursusci/index.php/controller and http://localhost/etalasekursusci/index.php/user work fine, just this one which fails.
我在http://localhost/etalasekursusci/index.php/controller上的控制器文件和http://localhost/etalasekursusci/index.php/user工作正常,只是这个失败了。
(FYI, I copy the user_authentication.php file from my friend. And if I copy the script inside user class to user_authentication class, the user_authentication.php can be accessed...) (仅供参考,我从我的朋友那里复制了user_authentication.php文件。如果我将用户类内的脚本复制到user_authentication类,则可以访问user_authentication.php ...)
The /application/.htaccess file : /application/.htaccess文件:
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>
The /application/config/config.php file : /application/config/config.php文件:
$config['base_url'] = 'http://localhost/etalasekursusci/';
The /application/config/routes.php file : /application/config/routes.php文件:
$route['default_controller'] = 'controller';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
The /application/controllers/user.php file (can be accessed): /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');
}
}
}
The /application/controllers/user_authentication.php file (which can't be accessed): /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);
}
}
Any ideas? 有任何想法吗?
(FYI, I copy the user_authentication.php file from my friend. And if I copy the script inside user class to user_authentication class, the user_authentication.php can be accessed...) (仅供参考,我从我的朋友那里复制了user_authentication.php文件。如果我将用户类内的脚本复制到user_authentication类,则可以访问user_authentication.php ...)
Since you have defined base url as 由于您已将基本网址定义为
$config['base_url'] = 'http://localhost/etalasekursusci/';
Please try url http://localhost/etalasekursusci/user_authentication without index.php 请在没有index.php的情况下尝试url http:// localhost / etalasekursusci / user_authentication
OR Define base_url in config as below with index.php 或者使用index.php在config中定义base_url
$config['base_url'] = ' http://localhost/etalasekursusci/index.php '; $ config ['base_url'] =' http://localhost/etalasekursusci/index.php ';
Please post controller code, If you can. 请发布控制器代码,如果可以的话。
In Codeigniter 3 your class names must start with an uppercase letter as should their filename. 在Codeigniter 3中,您的类名必须以大写字母开头,文件名也必须如此。
You should try rename user_authentication.php
to User_authentication.php
and change the opening lines to: 您应该尝试将
user_authentication.php
重命名为User_authentication.php
并将开头行更改为:
<?php
class User_authentication extends CI_Controller {
similarly, the user.php
should be changed to User.php
and its opening lines to: 同样,
user.php
应该更改为User.php
及其开头行:
<?php
class User extends CI_Controller {
The class documentation explaining this can be found here 可以在此处找到解释此的类文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.