科哈纳项目结构

发布于 2024-09-01 18:49:20 字数 525 浏览 9 评论 0原文

我正在研究在我的下一个项目中使用 Kohana。该网站将由用户注册(以及用户配置文件)组成,用户将拥有某些特权。该网站还将有一个管理部分,管理员可以在其中阻止用户或删除帖子或查看使用统计信息。一个好的比较网站将是一个多用户博客,其中每个博主根据她/他的权限可以发布/编辑/删除博客......仅作为示例。

首先,我不确定如何设置控制器/视图结构,以便将管理部分与前端站点分开。我正在使用 Kohana 3,所以我正在考虑像这样的控制器结构:application/classes/controller/front(面向前面)...和 ​​application/classes/controller/admin(用于管理部分)。

或者我注意到您可以使用 Route 类来设置路由,因此我可以设置“管理”路由。例如:www.example.com/admin 将进入管理员登录屏幕。 www.example.com --->前控制器。

另外,我是否可以以某种方式将“管理”视图和控制器与“正面”视图和控制器分开,例如根据文件夹结构将它们分开?非常感谢任何帮助。

谢谢。

I'm investigating using Kohana for my next project. The site will consist of user registration (and hence user profiles) where users will have certain privileges. The site will also have an admin section where administrators can go to say block a user or delete a post or look at usage statistics for example. A good comparison site would be a multi-user blog, where each blogger depending on her/his permissions can post/edit/delete blogs...just as an example.

Firstly, I'm not sure about how to set up the controller/view structure in order to separate the admin section from the front facing site. I'm using Kohana 3, so I was thinking of a controller structure like so: application/classes/controller/front (front facing)...and application/classes/controller/admin (for administrative section).

Or I notice you may be able to use the Route class to set up routes, so I could set up an "admin" route. for example: www.example.com/admin will lead to the admin logon screen.
www.example.com ---> front controller.

As well, can I somehow separate the "Admin" views and controllers from the "front facing" views and controllers like divide them up based on folder structure? Any help is very much appreciated.

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

↘人皮目录ツ 2024-09-08 18:49:20

您可以为管理和前端创建一个单独的应用程序文件夹:

  • application
    • 课程
      • 控制器
      • 型号
    • 观看次数
  • admin_application
    • 课程
      • 控制器
      • 型号
    • 观看次数

这种方法允许您单独定制每个引导环境,并很好地分离各个文件。但是,由于这种分离,您将需要将共享代码构建为模块,以允许在两个应用程序之间共享功能。当然,您可以复制代码,但现在这样做是错误的,不是吗! ;)

另一种方法是在单个应用程序的每个文件夹中都有管理子文件夹:

  • application
    • 课程
      • 控制器
        • 管理员
      • 型号
        • 管理员
    • 观看次数
      • 管理员

这种方法会使文件更加混合,并且可能使维护变得更加困难(取决于您的观点),但它肯定更容易实现。这种方法的一个优点是您可以创建一个 /public_html/admin 文件夹并使用 .htaccess 对其进行保护(您还需要添加普通 index.php 文件的副本)。然后,每当发出任何 http://yourdomain.com/admin 请求时,.htaccess 文件就会启动并在网络服务器级别保护您的管理应用程序。另外,请求将自动路由到各个文件夹中的 /admin 子文件夹,因此您在路由方面的工作量也更少。

这两种情况都将使用 Kohana 的(很棒的)路由机制来处理哪些请求去了哪里,并且从应用程序访问的角度来看,每种情况都与另一种情况一样安全。顺便说一句,我假设你正在使用 KO3...

编辑
实际上,如果您也使用第一种方法,您就可以 .htaccess 保护管理应用程序。您只需要调整 /admin/index.php 文件以指向管理应用程序。

You could have a separate application folder for the admin and front-end:

  • application
    • classes
      • controller
      • model
    • views
  • admin_application
    • classes
      • controller
      • model
    • views

This approach would allow you to customise each bootstrap environment individually, and separates the various files nicely. However, due to this separation you will need to structure shared code as modules, to allow the functionality to be shared across the two apps. You could just duplicate the code of course, but that would wrong now, wouldn't it! ;)

Another approach would be to have admin subfolders within each folder of a single application:

  • application
    • classes
      • controller
        • admin
      • model
        • admin
    • views
      • admin

This approach leaves files a little more intermixed, and might make things harder to maintain (depending on your perspective), but it's certainly easier to implement. One advantage of this approach is that you can create a /public_html/admin folder and protect it using .htaccess (you'll need to add a copy of the normal index.php file too). Then whenever any http://yourdomain.com/admin requests are made, the .htaccess file will kick-in and protect your admin application at the webserver level. Plus, the request will automatically route to the /admin subfolders within the various folders, so you've also got less work to do when it comes to routing.

Both situations would use Kohana's (awesome) routing mechanisms to handle which requests went where, and each is as secure as the other from an application access point of view. I've assumed you're using KO3 by the way...

EDIT
Actually, you are able to .htaccess protect the admin app if you use the first method too. You'd just need to adapt the /admin/index.php file to point to the admin app.

愿与i 2024-09-08 18:49:20

我的方法与第一个类似,但是对于每个模块,我将创建一个管理控制器和一个前端控制器 - 我的所有管理控制器都将从抽象管理控制器继承,该抽象管理控制器将在之前的方法中进行身份验证 - 或类似的方法。

My approach would be similar to the first one but then for each module I would create a admin controller and a frontend controller - All my admin controllers would inherit from an abstract admin controller that would have the authentication in the before method - or something like this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文