2012-02-17 104 views
3

我對ZF模塊和模型的結構有一些疑問。Zend Framework 2上的模塊和模型組織

(我說的是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? 

我真的堅持這個問題。 A無法在任何地方找到答案... 如果有人有這樣一個小應用程序,你不介意分享,我會很高興。

如果我不清楚我的問題,請詢問!

謝謝你的幫助。

回答

3

在這裏看到的是一個數據庫模型,因此我的主要問題是如何管理數據。在MVC模式中,您可以使用模型管理數據。盡我所能在這裏告訴你的問題不應與ZF2相關或限制。就像在早期版本中一樣,您應該有模型來管理數據庫和數據表。

模塊將處理應用程序方面。當你有一個可靠的數據模型(人物,流派,用戶,電影)時,你可以創建數十個訪問模型的模塊。因此,您可以爲不同目的準備很多很多模塊,但始終是相同的模型。

你可以有一個模塊,只處理用戶管理,一個只有管理(添加/更新)電影和另一隻列表(讀)電影等

1

我認爲你可以完成大部分的這一個ZF2模塊,可能被稱爲「MovieManager」。 Movie和Person可以是MovieManager模塊名稱空間中的模型(即基類和數據庫表)。

用戶可能是一個單獨的模塊,用於處理用戶身份驗證和訪問控制。您可以看看Evan Coury在可重複使用的ZF2用戶模塊上所做的工作:https://github.com/Zf-Commons/ZfcUser或者您可以保持簡單,並將用戶模型放入MovieManager模塊中。

我會使用Zend_Acl來定義允許給定用戶執行什麼操作。或者,您可以通過在User類中擁有基本的「角色」屬性並檢查MovieManager控制器中的授權角色來實現這一點。