路由时控制器在codeigniter php中不工作

pbpqsu0x  于 2022-10-30  发布在  PHP
关注(0)|答案(2)|浏览(148)

路由.php

当路由到其它路由时,出现此错误
服务器上没有找到请求的URL
为什么会出现此错误?
在routes.php中,setAutoRoute被设置为“true”,但是路由没有连接到控制器。

<?php

namespace Config;

// Create a new instance of our RouteCollection class.
$routes = Services::routes();

// Load the system's routing file first, so that the app and ENVIRONMENT
// can override as needed.
if (file_exists(SYSTEMPATH . 'Config/Routes.php'))
{
    require SYSTEMPATH . 'Config/Routes.php';
}

/**
 * --------------------------------------------------------------------
 * Router Setup
 * --------------------------------------------------------------------
 */
$routes->setDefaultNamespace('App\Controllers');
$routes->setDefaultController('Home');
$routes->setDefaultMethod('index');
$routes->setTranslateURIDashes(false);
$routes->set404Override();
$routes->setAutoRoute(true);

/*
 * --------------------------------------------------------------------
 * Route Definitions
 * --------------------------------------------------------------------
 */

// We get a performance increase by specifying the default
// route since we don't have to scan directories.
$routes->get('/', 'Home::index');
$routes->add('login', 'Home::login');
$routes->add('change-password/(.*)', 'Home::change_password');
$routes->add('logout', 'Home::logout');
$routes->add('available_inventory', 'Inventory::available_inventory');
$routes->add('sold_inventory', 'Inventory::sold_inventory');
$routes->add('reserved_inventory', 'Inventory::reserved_inventory');
$routes->add('agent_deal', 'Inventory::agent_deal');
$routes->add('employee_deal', 'Inventory::employee_deal');
/*
 * --------------------------------------------------------------------
 * Additional Routing
 * --------------------------------------------------------------------
 *
 * There will often be times that you need additional routing and you
 * need it to be able to override any defaults in this file. Environment
 * based routes is one such time. require() additional route files here
 * to make that happen.
 *
 * You will have access to the $routes object within that file without
 * needing to reload it.
 */
if (file_exists(APPPATH . 'Config/' . ENVIRONMENT . '/Routes.php'))
{
    require APPPATH . 'Config/' . ENVIRONMENT . '/Routes.php';
}
mbjcgjjk

mbjcgjjk1#

我建议你,读一读CI4的代码标准。也许是控制器可以帮助你。
其他事项:参见控制器的默认入口函数。默认情况下称为“索引”或“主”,取决于CI4版本

3qpi33ja

3qpi33ja2#

基于CI4路由,也许你可以尝试$routes->get('...而不是$routes->add('...

相关问题