php - Codeigniter - 404 页面未找到

标签 php .htaccess codeigniter model-view-controller http-status-code-404

我正在使用 Codeigniter。一切都很好,直到我创建名为 user_authentication.php 的新 Controller (位于 http://localhost/etalasekursusci/index.php/user_authentication )。当我尝试打开此 Controller 时,浏览器显示“404 页面未找到。未找到您请求的页面”。我的 Controller 文件在 http://localhost/etalasekursusci/index.php/controllerhttp://localhost/etalasekursusci/index.php/user工作正常,只有这个失败了。

(仅供引用,我从 friend 那里复制了 user_authentication.php 文件。如果我将用户类中的脚本复制到 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);
}

}

有什么想法吗?

(仅供引用,我从 friend 那里复制了 user_authentication.php 文件。如果我将用户类中的脚本复制到 user_authentication 类,则可以访问 user_authentication.php...)

最佳答案

因为您已将基本 url 定义为

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

请尝试 url http://localhost/etalasekursusci/user_authentication没有 index.php

或者在 config 中用 index.php 定义 base_url

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

如果可以,请发布 Controller 代码。

关于php - Codeigniter - 404 页面未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30285757/

相关文章:

apache - 使用 .htaccess 重定向域后的所有内容

javascript - 我在 codeigniter 中的 AJAX 登录表单始终选择 else 语句,即使满足条件也是如此。这些怎么解决呢?

php - CodeIgniter - 通过表单上传图像,将图像的位置存储在数据库中

php - 2 个并发 AJAX 上的 CodeIgniter $this->session->set_userdata()

php - 拼字游戏生成器

php - 如何在从 bitnami 安装的 linux 上查找 wordpress 文件

php - 我们如何在 ConfigureIT 管理或数据面板的产品模块列表中显示产品价格的总计

.htaccess - htaccess 重写 url - 将文件夹重定向到 php 文件

php - 从漂亮的网址获取变量

php - 在 AngularJs 中使用 MySQL 和 PHP 嵌套 JSON 数据 | ng选项