【发布时间】:2022-11-07 07:03:22
【问题描述】:
我在 Codeigniter 4.2.6 中使用 URI 路由时遇到问题。我有控制器名称
Home
和方法名称
getIndex
。访问
http://localhost:8080
时一切正常。当我尝试
http://localhost:8080/home/index
时,会出现一条消息
'Cannot access the default controller "Home" with the controller name URI path'
。我设置了
$routes->setAutoRoute(true);
和
public bool $autoRoutesImproved = true;
。当我创建另一个方法
getAbout
时同样的问题。访问
http://localhost:8080/home/about
也会产生一条消息
Cannot accessing...
。
使用
Sub directory
分离逻辑时同样的问题。这是我的子目录名称代码
Admin
:
并尝试访问它得到相同的结果
Cannot access the default controller "Home" with the controller name URI path.
那么如何在 codeigniter 4 中使用 URI 路由,尤其是 4.2.6 使用 Auto Routing enable 和 Manual Routing 呢?
先感谢您。
更新
这是我的 Routes.php
setDefaultNamespace('App\Controllers');
$routes->setDefaultController('Home');
$routes->setDefaultMethod('index');
$routes->setTranslateURIDashes(false);
$routes->set404Override();
// ...
// If you don't want to define all routes, please use the Auto Routing (Improved).
// Set `$autoRoutesImproved` to true in `app/Config/Feature.php` and set the following to true.
$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');