是什么导致我的 Codeigniter 3 应用程序出现“找不到页面”错误?

What causes this Page Not Found error in my Codeigniter 3 application?

我正在 blog application Codeigniter 3.1.8 和 Bootstrap 4.

我已经为这个应用程序添加了一个注册和登录系统。我目前正在研究密码重置系统。

Changepasword控制器中,index方法接受参数$email$token:

public function index($email, $token) {
    $data = $this->Static_model->get_static_data();
    $data['pages'] = $this->Pages_model->get_pages();
    $data['tagline'] = 'New password';
    $data['categories'] = $this->Categories_model->get_categories();

    // Form validation rules
    $this->form_validation->set_rules('password', 'Password', 'required|min_length[6]');
        $this->form_validation->set_rules('cpassword', 'Confirm password', 'required|matches[password]');
    $this->form_validation->set_error_delimiters('<p class="error-message">', '</p>');

    if(!$this->form_validation->run()) {
        $this->load->view('partials/header', $data);
        $this->load->view('auth/newpassword');
        $this->load->view('partials/footer');
    } else {
        $this->Usermodel->set_new_password($email, $token);
    }
}

在路由文件中,我为上述控制器设置了这一行:

$route['changepasword/(:any)/(:any)'] = 'changepasword///';

整个路由文件:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

$route['default_controller'] = 'posts';
$route['install'] = 'install';
$route['migrate'] = 'migrate';
$route['register'] = 'register';
$route['login'] = 'login';
$route['newpassword'] = 'newpassword';
$route['changepasword'] = 'changepasword';
$route['changepasword/(:any)/(:any)'] = 'changepasword///';
$route['dashboard'] = 'dashboard';
$route['dashboard/create-post'] = 'dashboard/posts/create';
$route['dashboard/create-page'] = 'dashboard/pages/create';
$route['dashboard/create-category'] = 'dashboard/categories/create';
$route['dashboard/manage-authors'] = 'dashboard/users';
$route['404_override'] = '';
$route['categories/posts/(:any)'] = 'categories/posts/';
$route['(:any)'] = 'posts/post/';
$route['translate_uri_dashes'] = FALSE;

我还将此添加到 config.php 文件中:

$config['permitted_uri_chars'] = 'a-z 0-9~%.:_()@=&\-!';

然而,在 URL http://ciblog.com/changepasword/myaddress@gmail.com/f450469ac1970b06074acb7c430d431d 而不是渲染视图时,我得到了错误:

404 Page Not Found
The page you requested was not found.

如果我使用 md5($this->user_email) 而不是 $this->user_email,我会得到 URL:http://ciblog.com/changepasword/ec9814883d7f7149bc15f1ed1f472da9/d7571dc4e25ea76278bee5eb45251f11,但 404 找不到页面 错误消息。

到目前为止我为这个更新密码功能编写的所有代码是HERE.

我做错了什么?

更改这两行!

$route['changepasword'] = 'changepasword';
$route['changepasword/(:any)/(:any)'] = 'changepasword///';

更新: 你忘记在路由中定义 function/method 名称: 从这个修改:$route['newpasword/(:any)/(:any)'] = 'newpasword///'; 到这个:$route['newpasword/(:any)/(:any)'] = 'newpasword/index///'; 并且上一行 ($route['newpasword'] = 'newpasword';) 是可删除的,因为你没有使用不带参数的索引函数。