Cakephp 如何从管理文件夹设置根页面?

Cakephp how to set root page from admin folder?

Routes.php

$routes->scope('/', function (RouteBuilder $builder) {
    $builder->connect('/', ['controller' => 'Users', 'action' => 'login']);
    $builder->connect('/pages/*', 'Pages::display');
    $builder->fallbacks();
});

文件结构

如何将管理员登录页面添加为网站的根页面?

像这样

   $routes->scope('/Admin/UserController', function (RouteBuilder $builder) {
       $builder->connect('/Admin/UserController', ['controller' => 'Users', 'action' => 'login']);
   });

这不是你应该如何连接路线,你不要在你的路径中放置 UserController 之类的东西,路径定义了 URL 格式!

如果你想连接/到你的管理员前缀控制器,那么你需要相应地在路由默认值中传递prefix选项,例如:

$routes->scope('/', function (RouteBuilder $builder) {
    // connect the URL `/` to `\App\Controller\Admin\UsersController::login()`
    $builder->connect('/', [
        'prefix' => 'Admin',
        'controller' => 'Users',
        'action' => 'login',
    ]);
    // shorthand variant of the above
    // $builder->connect('/', 'Admin/Users::login');

    $builder->connect('/pages/*', 'Pages::display');
    $builder->fallbacks();
});

另见