如何在cakephp中为管理员创建单独的目录 [英] How to create a seperate directory for admin controller in cakephp

查看:59
本文介绍了如何在cakephp中为管理员创建单独的目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Cakephp开发的新手。我已经创建了用于注册,登录和登录的用户控制器。在用户表中更新自己的配置文件。我可以通过 http:// local-host / my_project / user / login 访问用户控制器。

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.

我在数据库中也有一个admin表,以便admin可以登录和管理项目中的用户。我想在控制器目录中创建一个单独的文件夹(例如:admin),以便我可以使用 http:// local-host / my_project / admin / controller / login & http:// local-host / my_project / admin / controller / manage

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.

推荐答案

您应该在手册中查看前缀路由,看来这就是您要查找的内容:

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#前缀路由

使用前缀路由,您可以向用户控制器添加一个操作admin_overview(),然后可以对其进行访问通过URL / admin / users / overview。带有 admin前缀的操作将与非管理员操作(例如 overview())重叠,并且可以通过常规 URL进行访问; / users / overview /

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/

当然,您可以为此创建单独的管理控制器,但是您可能需要创建自定义路由。要获得有关路由的更高级选项,您值得花时间阅读整章(甚至更好)来阅读整本蛋糕食谱,也可以将其作为电子书以供离线阅读;
http://book.cakephp.org/2.0/en/index.html

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 -插件

这篇关于如何在cakephp中为管理员创建单独的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆