0

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?

SrQ
  • 106
  • 7

1 Answers1

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