Reputation: 2551
In my Cakephp application i wish to have the following url:
admin/users/:action
I want the UsersController to reside in an sub-folder of Controllers named 'admin'. I know how to implement this with Cake 3 and 4 but in this case I am working with a legacy Cake2 project. I have read the chapter on the router in the Cake2 book, but it seems to deal with this by prefixing controller actions with "admin" using a single main controller.
That's not what I need, I am looking for the following:
Controllers
- [Admin]
- UsersController
- UsersContrller
That is - two controller and the sub-folder.
I can match the route as follows, but I can't figure out the parameters to use:
Router::connect(
'/integrations/foo/:controller/:action/*',
[]
);
Where 'integrations' is my plugin and 'foo' is the sub-folder. I am having doubts if this is actually possible in Cake2. I found an old question from 2013 that says that sub-directories for controllers is no longer supported, but I am not sure if that is a valid statement.
CakePHP controllers and models in subdirectory
Might this need to be done with a redirect at the server level?
Upvotes: 0
Views: 257
Reputation: 482
In your routes.php, do the following:
Router::connect('/admin',array('controller' => 'users', 'action' => 'login', 'admin' => true));
for example!
This will redirect you to: yoursite.com/admin
This way, you can follow your structure normally with your controllers inside the admin folder.
In the example I gave, it would look like this: admin/users/login.php
Upvotes: 1