Zend Framework 2 上的模块和模型组织

发布于 2025-01-06 18:33:17 字数 1447 浏览 1 评论 0原文

我对 ZF 模块和模型的结构有一些疑问。

(我说的是ZF 2,因为我放弃了ZF 1.11)

为了让我的问题简单易懂,看下面的例子: (我创建这个只是为了学习 ZF2)

Movie Manager DataBase

这是一个“电影管理器应用程序”。 在这个应用程序中,我有 3 种用户:

- visitors: peolple who olny can see the movies in the database.
- members: same as visitors plus insert, update and delete movies.
- administrator: same as members plus insert, update and delete users and other informations as genre, artist, ...

成员只能插入新电影,即他们不能 插入一个新的流派,而不是一个新的艺术家。

好的...对于这个问题,我找到了这个解决方案:

- create 3 modules: visitor, member, admin;

但我不确定这是否是组织程序的最佳方式...

我意识到ZF希望人们以这种方式组织应用程序:

- create modules for each funcionallity;
- create roles for each kind of user;

所以,我的问题是:

1. My solution is right or wrong?
2. If my solution is right, how can I organize my application?
3. How can I organize my models, to be visible to more than one module?
- I think a should create a model "movie" somewhere if "inserts, updates, deletes, and selects"
then a module "visitor" could only use a "select" while a module "member" could use all the funcionallities. Am I right?

4. If my solution is not right, how can I organize my application?
5. How should be my modules?

我真的遇到这个问题。 到处都找不到答案... 如果有人有像这样的小应用程序并且您不介意分享,我会很高兴。

如果我不清楚我的问题,请提问!

感谢您的帮助。

I have some questions about the structure of ZF modules and models.

(I'm talking about ZF 2, because I gave up of ZF 1.11)

To make my question simple to understand, look at the following example:
(I create this just to learn ZF2)

Movie Manager DataBase

It's a "movie manager application".
In this application I have 3 kind of users:

- visitors: peolple who olny can see the movies in the database.
- members: same as visitors plus insert, update and delete movies.
- administrator: same as members plus insert, update and delete users and other informations as genre, artist, ...

members can't insert nothing more than a new movie, i. e., they can't
insert a new genre, neither a new artist.

ok... for this problem, I found this solution:

- create 3 modules: visitor, member, admin;

but I'm not sure if it's the best way of organize de program...

I realize that ZF expects people organize application this way:

- create modules for each funcionallity;
- create roles for each kind of user;

so, my questions are:

1. My solution is right or wrong?
2. If my solution is right, how can I organize my application?
3. How can I organize my models, to be visible to more than one module?
- I think a should create a model "movie" somewhere if "inserts, updates, deletes, and selects"
then a module "visitor" could only use a "select" while a module "member" could use all the funcionallities. Am I right?

4. If my solution is not right, how can I organize my application?
5. How should be my modules?

I really stuck with this problem.
A couldn't find answers anywhere...
If someone have a little application like this one and you don't mind to share, I'll be glad.

if I'm not clear at my questions, please ask!

Thank you for your help.

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

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

发布评论

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

评论(2

醉殇 2025-01-13 18:33:17

这里看到的是数据库模型,因此对我来说主要问题是如何管理数据。在 MVC 模式中,您可以使用模型来管理数据。据我所知,您的问题不应该与 ZF2 相关或仅限于 ZF2。与早期版本一样,您应该有模型来管理数据库和数据表。

这些模块将处理应用程序方面。当您拥有可靠的数据模型(人物、流派、用户、电影)时,您可以创建数十个访问模型的模块。因此,您可以拥有大量用于不同目的的模块,但始终具有相同的模型。

您可以拥有一个仅处理用户管理的模块,一个仅管理(添加/更新)电影的模块,另一个仅列出(读取)电影等。

What is see here is a database model and therefore the main question for me is how to manage the data. In a MVC pattern you manage data with models. As much as I can tell here your question should not be related or limited to ZF2. Like in earlier versions you should have models to managed the database and data tables.

The modules will handle the application aspect. When you have a solid model for the data (people, genre, users, movies) you can create dozens of modules accessing the models. Hence you can have lots and lots of modules for different purposes but always the same model.

You can have a module that only handles user management, one that only manages (add/update) movies and another that only list (read) movies, etc.

一百个冬季 2025-01-13 18:33:17

我认为您可以在一个 ZF2 模块(可能称为“MovieManager”)中完成大部分工作。 Movie 和Person 可以是MovieManager 模块命名空间内的模型(即基类和数据库表)。

用户可以是一个单独的模块,用于处理用户身份验证和访问控制。您可以看一下 Evan Coury 在可重用 ZF2 用户模块上所做的工作:https://github .com/Zf-Commons/ZfcUser 或者您可以保持简单并将 User 模型也放入您的 MovieManager 模块中。

我将使用 Zend_Acl 来定义允许给定用户执行哪些操作。或者,您可以通过在 User 类中拥有基本的“角色”属性并检查 MovieManager 控制器中的授权角色来更简单地做到这一点。

I think you could do most of this in one ZF2 module, maybe called "MovieManager". Movie and Person could be models (i.e. base classes and database tables) within the MovieManager module's namespace.

User could be a separate module, for handling user authentication and access control. You might take a look at the work that Evan Coury has done on a reusable ZF2 user module: https://github.com/Zf-Commons/ZfcUser Or you could keep it simple and put the User model inside your MovieManager module as well.

I would use Zend_Acl to define what operations a given User is allowed to perform. Or you could do that more simply by having a basic "role" property in the User class and checking for authorized roles in your MovieManager controllers.

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