How to create a seperate directory for admin controller in cakephp

蓝咒 提交于 2019-12-08 07:56:50

问题


I am new to cakephp development. I have create user controller to register, login & update own profile in the user table. I can access the user controller with http://local-host/my_project/user/login.

I have also a admin table in database so that admin can login and manage user in my project. I want to create a folder separate folder (ex: admin) in the controller directory so that i can access the controller files using http://local-host/my_project/admin/controller/login & http://local-host/my_project/admin/controller/manage.


回答1:


You should have a look at 'prefix routing' in the manual, it seems that this is what you're looking for:

http://book.cakephp.org/2.0/en/development/routing.html#prefix-routing

With prefix routing, you'll be able to add, for example, an action admin_overview() to your User controller which is then accessible via the URL /admin/users/overview. The 'admin' prefixed action will not overlap with non-admin actions (e.g. 'overview()'), which will be accessible via the 'regular' URL; /users/overview/

Of course, you can create separate admin controller(s) for this purpose, but you may need to create custom routes. For more advanced options regarding routing, it's worth your time to read the whole chapter (or, even better) read the whole cake cookbook, it's also available as eBook for offline reading; http://book.cakephp.org/2.0/en/index.html

Another solution is to develop the 'admin' part of your application as a plugin. This will keep your frontend and backend controllers/models/views separated. As a bonus, the backend may can be re-used for other projects as well (depending on its design of course)

http://book.cakephp.org/2.0/en/plugins.html#creating-your-own-plugins



来源:https://stackoverflow.com/questions/14909579/how-to-create-a-seperate-directory-for-admin-controller-in-cakephp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!