一般来说分裂admin和Web应用程序分成两个实体 [英] Generally splitting admin and web app into two entities

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

问题描述

我建立一个面向公众的网络/移动应用程序,将有一个实质性的管理员控制的后端。虽然这个问题是相当普遍的,我使用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.

我也想过发展,无论是前端和后端将分享基于REST风格的CakePHP 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?

推荐答案

我认为这是最好的,以保持双方管理功能和REST API在主CakePHP的应用程序。 (你不指定版本,但我假设,因为你让你使用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.)

马克提到的,你可以做一些所谓的 preFIX路由,允许你创建,只有管理员可以在现有的控制器使用专项治理行动。有一个在 preFIX路由文档的完整解释

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.

要点是你指定你想要的preFIX的 core.php文件的:

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

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

所以要/管理/用户/编辑/ 5会调用该方法 admin_edit 我们的 UsersController 经过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.

您可以设置一个默认的admin的主页的 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,这是一个内置的是pretty容易打开。有一个在 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应用程序分成两个实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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