SrQ
SrQ

Reputation: 106

Cakephp 4.x Admin Authentication repeated Controllers needed?

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?

Upvotes: 0

Views: 188

Answers (1)

ndm
ndm

Reputation: 60493

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.

Upvotes: 1

Related Questions