If I have a UsersController and want to have an admin Prefix, do I need to have one controlle for all basic user functions, and another UsersController inside /Admin with only admin functions? Am I supposed to have two UsersControllers in my code?
Asked
Active
Viewed 163 times
1 Answers
1
If you want to use CakePHP's prefix functionality, then yes, you'll have two UsersController
classes, that's how it's supposed to be. It's not a problem as prefixes do map to namespaces, so the controllers will live in different namespaces, one in App\Controller
and one in App\Controller\Admin
.
If you bake the controllers they'll automatically land in the right place:
bin/cake bake controller Users
bin/cake bake controller Users --prefix Admin
To share common functionality between both controllers, look into using components.

ndm
- 59,784
- 9
- 71
- 110
-
I didn't know that second bake option for prefix. That's great. Thanks! – SrQ Apr 18 '20 at 18:53