开发者

Nested Controllers

开发者 https://www.devze.com 2023-02-16 15:27 出处:网络
Is there a way to have nested controllers or at least to looks like that,like in codeigniter eg. /admin/controller

Is there a way to have nested controllers or at least to looks like that,like in codeigniter eg.

/admin/controller

where admin is a dir 开发者_如何转开发inside Controllers forlder.

/admin/users_controllers.php where you put everything in there.

I know that I can achieve this with routes, but just curious if I can do this for architecture of app.


I think that organizing things this way mixes controller and authentication logic. In CakePHP your actions are grouped by controller, and controllers are usually in correspondence with models. So you will have controllers for users, posts, products or whatever.

Then, for each controller, some actions may only be available to users with certain privileges, for instance admins. You should not create a separate controller to distinguish the privilege level, but rather group your actions according to the data they act opon. It is the task of the Auth component, possibly working together with other components such as Acl, to grant or deny access to the single actions in each controller.

As you already know, you can then prefix actions which need admin privileges by admin using routing. This gives a separate entry point for the action, but the controller managing the logic reamins the same.

So the answer to your question is: you shouldn't. This is not what controllers are for; controllers are for grouping actions on the same objects, not to group actions requiring different access levels.

0

精彩评论

暂无评论...
验证码 换一张
取 消