0

嗨,伙计们,我对如何在基于 Zend Framework 的应用程序中使用模块感到有些困惑——从我读过的关于模块在您的应用程序中作为子应用程序工作的内容来看,但是模块中的内容和模块中的内容之间的界限在哪里模糊可以在控制器内处理。例如,在家庭预订应用程序中,您具有以下功能:

房屋管理 房价管理 网上订房+订房管理

考虑到我们有三种类型的用户:管理员用户、进行预订的客户和拥有用于预订的房屋的房东如何设置我们的模块,即我们是否会有类似的内容:

admin
->controllers
  ->houseController
  ->rateController
  ->bookingController
  ->customersController
landlord
->controllers
  ->houseController
  ->rateController
  ->bookingController
customer
->controllers
  ->bookingController

还是会是这样的:

modules
->Booking
->Rate
->Customers

后一种格式似乎有点像将控制器变成模块 - 这里的正确方法是什么?

在原始列表中 - 每个模块中有重复的控制器。差别非常小,例如:管理模块中的houseController - 管理员可以查看所有房东的所有房屋,而房东只能查看他们自己的房屋。从技术上讲,我在这里重复了 90% 的代码,这似乎不是正确的做法,因为我认为您不能使用 ACL 来限制可以查看的列表。这种逻辑的正确方法是什么?

4

3 回答 3

1

在我看来,这些功能中的大部分似乎更适合模型。您也许可以只使用带有属性控制器的默认模块,该控制器为客户和所有者提供不同的视图,并且可能为管理员提供一个单独的模块,因为管理员通常具有管理所需的更多功能。

//bare minimum, you may need to add controllers andd models for user/owner objects and rate managment
/application
    /controllers
        /IndexController // default entry to application, login, authentication
        /ErrorController
        /PropertyController // actions to view, book and reserve a property object, may provide some extra functions for owners.
    /modules
        /admin
            /IndexController // provides actions for administration activities such as managing user and owners and setting ACL and Authentication.

这只是我的观点,请记住 ZF1 中的模块与 ZF2 中的模块完全不同。

于 2013-01-02T10:10:32.103 回答
1

好的。让我们试着回答它...

这是一个经典的优化挑战(关于应用程序架构)。根据您的目标,您将有不同的优化方法。我更喜欢针对产生的技术功能优化应用程序架构。如果您想要的模块的功能

  • 行政
  • 房东
  • 顾客

具有不同的功能范围,将它们分开(这也将简化 ACL 定义)。

根据您在问题中发布的内容,有一些控制器“重叠”:

  • 房屋控制器
  • 速率控制器
  • 预订控制器

它们被多次使用。在功能方面,它们应该只在一个模块中使用。如果您不能将它们分开,则无需单独的模块...

希望这能让您大致了解如何使用模块。

于 2013-01-01T10:16:09.553 回答
0

While the question is old I feel it still hasn't been answered. I myself have been setting up an e-commerce CMS project for the last few days and learning the basics of Zend Framework coming from a silver light Prism background. One thing that I can suggest is to understand that a module doesn't need to be small. The very definition of a module is "An independent self-contained unit" so in your case you'll have a "BookingModule" that when finished should be able to be chucked into any application and then with the proper tie ins can communicate with other modules. The issue with your layout is your relying on the modules to separate your different levels of access (which in a reply you basically ask "how should I do this"), what you want todo is use some sort of Authentication method to see if the current user can run a specific action. Off what you've given us I'd suggest a role based authentication method with maybe multiple actions (still deciding this part for myself).

Zend Framework

  • Hosts an "Application" which contain modules that utilize MVC

Module

  • An independent self-contained unit that can be plugged into any application
  • Can have hooks/tie-ins to communicate to other modules within an application

MVC

  • Models: Insure Data integrity through Validation verification
  • Views: Displays the Model's Data to the user
  • Controllers: Process user input through Actions that edit Data
    • Action: Security logic should go here, to ensure the user can use this action.

Role

  • An Enum for use in Authentication

TL;DR For your project you should have 1 module, 4 controllers, 3 roles and an authorization Service tied to your controller's actions to verify the current user can run said action. This'll prevent repeating code and also allow it to be expandable without any code rewrites.

Read this to understand Authorization on Actions: Activity based checks

Edit: Should probably note that there is nothing wrong with making each one a module as it is workable, its just more work to tie in and more coding with the only gain being you could pull say the Bookings Module into a completely different Application without the need for the other 2. But from my understanding you just want 1 module

于 2013-04-15T05:20:07.947 回答