我正在尝试在 CakePHP3 中使用前缀路由。我在 /config/routes.php 中添加了以下几行。
Router::prefix("admin", function($routes) {
// All routes here will be prefixed with ‘/admin‘
// And have the prefix => admin route element added.
$routes->connect("/",["controller"=>"Tops","action"=>"index"]);
$routes->connect("/:controller", ["action" => "index"]);
$routes->connect("/:controller/:action/*");
});
之后,我创建了 /src/Controller/Admin/QuestionsController.php,如下所示。
<?php
namespace App\Controller\Admin;
use App\Controller\AppController;
class QuestionsController extends AppController {
public function index() {
//some code here
}
}
?>
最后我尝试访问localhost/app_name/admin/questions/index
,但我得到一个错误,说,Error: questionsController could not be found
。但是,当我将控制器名称的第一个字母大写时(即 localhost/app_name/admin/Questions/index),它工作正常。我觉得这很奇怪,因为没有前缀,我可以使用第一个字符不大写的控制器名称。这是某种错误吗?