I'm trying to set up prefix routing but only on certain controllers where I would want a separate admin version but I only seem to be able to make it work for all or nothing.
$routes->prefix('admin', function ($routes) {
$routes->connect('/:controller/:action/*', [], ['routeClass' => 'Cake\Routing\Route\InflectedRoute']);
});
The above creates an admin prefix on every controller such that when i am within /admin/ all links to any controller created with the HTML helper have the admin prefix added to them and even when I'm redirected to login it is prefixed with /admin/. I would need to create admin version of every controller or specify on every link prefix=>false.
I assumed it would be something like:
$routes->prefix('admin', function ($routes) {
$routes->connect('/projects/:action/*', ['controller' => 'Projects'], ['routeClass' => 'Cake\Routing\Route\InflectedRoute']);
});
but with this code when accessing a page within /admin/projects i get the error: Error: A route matching "array ( 'controller' => 'Users', 'action' => 'login', 'prefix' => 'admin', 'plugin' => NULL, '_ext' => NULL, )" could not be found.
As if it is trying to redirect me to login, even though if i revert the code back the page loads and I have not been logged out.
Thanks in advance for your help.