一般将 admin 和 web app 分成两个实体 [英] Generally splitting admin and web app into two entities

查看:26
本文介绍了一般将 admin 和 web app 分成两个实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个面向公众的网络/移动应用程序,它将拥有一个由管理员控制的强大后端.虽然这个问题很笼统,但我使用 CakePHP 来构建应用程序.

I am building a public facing web/mobile application that will have a substantial admin controlled back end. Although this question is quite general, I am using CakePHP to build the application.

我正在研究将管理应用程序和公共应用程序拆分为两个应用程序是否明智.这两个应用程序将使用相同的数据库.我对此进行研究的主要原因是为了提高安全性,以及前端的可移植性.

I am looking into whether it would be wise to split the admin and public applications into two applications. Both applications would use the same database. The main reason I am looking into this would be for improved security, but also portability of the front end.

我还考虑开发一个前端和后端共享的基于 CakePHP 的 RESTful API.

I have also thought about developing a CakePHP based RESTful API that both the front and back end would share.

API 是解决这个问题的最佳方式,还是每个应用程序应该只共享数据库,或者拆分应用程序只是从长远来看创造更多工作?

Would an API be the best way to go about this or should each application simply only share the database, or is splitting the applications just creating more work in the long run?

推荐答案

我认为最好在主 CakePHP 应用程序中同时保留管理功能和 REST API.(您没有指定版本,但我假设您正在制作一个新应用,您使用的是 2.0.它有以下一些好处.)

I think it's best to keep both the Admin functionality and REST API in your main CakePHP application. (You don't specify a version, but I'm assuming since you're making a new app you're using 2.0. It has some benefits below.)

正如马克提到的,您可以执行称为前缀路由的操作,它允许您创建只有管理员才能在现有控制器中使用的特殊操作.前缀路由文档中有完整的解释.

As mark mentioned you can do something called prefix routing that allows you to create special actions that only admins can use in your existing controllers. There's a full explanation in the Prefix Routing docs.

要点是您在 core.php 中指定所需的前缀:

The gist is that you specify the prefix you want in core.php:

Configure::write('Routing.prefixes', array('admin'));

因此转到/admin/users/edit/5 将调用我们的 UsersController 的方法 admin_edit 传递 5 作为第一个参数.使用的视图文件将是/views/users/admin_edit.ctp.

So going to /admin/users/edit/5 would call the method admin_edit of our UsersController passing 5 as the first parameter. The view file used would be /views/users/admin_edit.ctp.

您可以在 routes.php 中设置默认的管理员"主页:

You can set a default "admin" homepage in routes.php:

Router::connect('/admin', array('controller' => 'pages', 'action' => 'index', 'admin' => true));

至于 REST API,如果您使用的是 2.0,这是一个很容易打开的内置程序.REST 页面上有一个很好的介绍.

As for the REST API, if you're using 2.0 this is a built-in that is pretty easy to turn on. There's a good intro on the REST page.

激活它只需要将这些行添加到routes.php:

Activating it just requires adding these lines to routes.php:

Router::mapResources('recipes');
Router::parseExtensions();

这会设置一些默认的 REST 路由:

This sets up some default REST routes:

#HTTP format URL.format              Controller action invoked
GET          /recipes.format         RecipesController::index()
GET          /recipes/123.format     RecipesController::view(123)
POST         /recipes.format         RecipesController::add()
PUT          /recipes/123.format     RecipesController::edit(123)
DELETE       /recipes/123.format     RecipesController::delete(123)
POST         /recipes/123.format     RecipesController::edit(123)

文档中有更多信息,请查看.

There's more info in the doc so please check it out.

这篇关于一般将 admin 和 web app 分成两个实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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