I'm building a site in CakePHP 5; I've made the main part of the site but now I'm building the admin area and getting an error.
I've set up my routes with an admin prefix, like this:
$routes->prefix('Admin', function (RouteBuilder $routes) {
$routes->connect('/', ['controller' => 'Pages', 'action' => 'index']);
$routes->connect('/pages/index', ['controller' => 'Pages', 'action' => 'index']);
$routes->fallbacks(DashedRoute::class);
});
I've created PagesController.php in src/Controller/Admin and it has an index function:
class PagesController extends AppController
{
public function initialize(): void
{
parent::initialize();
$this->loadComponent('Authorization.Authorization');
}
public function index($name = null)
{
$query = $this->Pages->find();
$query = $this->Authorization->applyScope($query);
$pages = $this->paginate($query);
$this->set(compact('pages'));
}
}
and I have templates/Admin/Pages/index.php.
When I try to navigate to http://localhost/sites/HMIPS/admin/pages/index I get the error Controller class `Pages` could not be found and a MissingControllerException.
What am I doing wrong?I've built similar sites before, but using CakePHP 4, so I don't know whether there's something new in version 5 that I'm missing. Is there anything else I need to set up to make this work?