何時在Zend Framework中使用模塊?

[英]When to use Modules in Zend Framework?


When setting up new ZF Projects i normaly have this directory structure:

在設置新的ZF項目時,我通常具有以下目錄結構:

  • application
    • modules
      • default
        • controller
        • forms
        • view
        • models
      • 默認控制器形成視圖模型

      • admin
        • controller
        • forms
        • view
        • models
      • 管理員控制器形成視圖模型

    • 模塊默認控制器表單視圖模型管理控制器表單視圖模型

    • language
    • shared
      • models
  • 應用模塊默認控制器表單視圖模型管理控制器表單視圖模型語言共享模型

  • library
  • public

I use only modules when e.g the layout is diffrent, or a diffrent database is used, or of course when its a very special case like a admin-backend or a forum/board. Then i have Controller for the different parts of the application. e.g JobController, ProductController and so on.

我只使用模塊,例如布局不同,或使用不同的數據庫,或者當它是一個非常特殊的情況,如admin-backend或論壇/板。然后我有應用程序的不同部分的控制器。例如JobController,ProductController等。

A colleague of mine showed me his base layout. its nearly the same, but he uses a lot of modules. like Job-Module, Product-Module each of this modules mostly have 2 Controllers an IndexController and an AdminController.

我的一位同事向我展示了他的基礎布局。它幾乎一樣,但他使用了很多模塊。像Job-Module,Product-Module這個模塊中的每個模塊大多有2個控制器,一個IndexController和一個AdminController。

His setup works and isnt wrong, but i never saw such an approach, its seems unneeded complicated.

他的設置工作並沒有錯,但我從未見過這樣的方法,它似乎不需要復雜。

So to come to an end:

所以要結束:

  1. When would you use Modules and when you would stick to Controllers?
  2. 你什么時候使用模塊,什么時候你會堅持使用控制器?

  3. Whats your rule to decide Module or not Module ?
  4. 您的規則是什么決定模塊或不模塊?

  5. What are the cons AND pros of my colleague's setup in your point of view?
  6. 在您的觀點中,我的同事設置的缺點和優點是什么?

  7. What are the cons AND pros of my setup in your point of view?
  8. 在您的觀點中,我的設置的缺點和優點是什么?

TIA

Rufinus

EDIT: see http://mwop.net/blog/2012-04-30-why-modules.html for info on the redesigned modules in ZF2.0

編輯:有關ZF2.0中重新設計的模塊的信息,請參閱http://mwop.net/blog/2012-04-30-why-modules.html

4 个解决方案

#1


9  

What are the cons AND pros of my colleague's setup in your point of view?

在您的觀點中,我的同事設置的缺點和優點是什么?

Better Reusability. Assuming your colleague kept the code inside the modules indepedent from other modules, he effectively created a self-contained problem domain. Unlike with your approach, he can more easily copy the entire module over to other applications then.

更好的可重用性。假設您的同事將代碼保留在與其他模塊無關的模塊內,他有效地創建了一個自包含的問題域。與您的方法不同,他可以更輕松地將整個模塊復制到其他應用程序。

#2


6  

When would you use Modules and when you would stick to Controllers?

你什么時候使用模塊,什么時候你會堅持使用控制器?

Same as you. For major sections of my website like the front-end, admin section, members section, etc...

和你一樣。對於我的網站的主要部分,如前端,管理部分,成員部分等...

Whats your rule to decide Module or not Module ?

您的規則是什么決定模塊或不模塊?

Is it part of the main site or its own little world just related to the front end? Especially in regards to design. How do you manage a couple of modules some using the same layout?

它是主要網站的一部分還是與前端相關的自己的小世界?特別是在設計方面。如何使用相同的布局管理一些模塊?

What are the cons AND pros of my colleague's setup in your point of view?

在您的觀點中,我的同事設置的缺點和優點是什么?

My God the maintenance. All these folders for nothing at all. Why have your about page and contact page in two different file structures? Also where does he put admin and members if he uses modules for simple pages?

我的上帝保養。所有這些文件夾什么都沒有。為什么您的頁面和聯系頁面有兩種不同的文件結構?如果他使用簡單頁面的模塊,他還把管理員和成員放在哪里?

What are the cons AND pros of my setup in your point of view?

在您的觀點中,我的設置的缺點和優點是什么?

Really the opposite of the above. Easy to understand and coherant structure.

真的與上面相反。易於理解和結合的結構。

Its worth it to add its the way the zend team intended us to use it link

它值得添加它的zend團隊打算我們使用它鏈接的方式

Another thing to think about is what will your urls look like.

另一件需要考慮的事情是你的網址會是什么樣子。

myapp.com/contact

myapp.com/about

myapp.com/members/profile

myapp.com/members/profile/edit

myapp.com/members/mail

This is one easy way to help organise what will go in modules or controllers.

這是一種簡單的方法來幫助組織模塊或控制器中的內容。

#3


5  

...like Job-Module, Product-Module each of this modules mostly have 2 Controllers an IndexController and an AdminController.

...就像Job-Module,Product-Module這個模塊中的每個模塊大多有2個控制器,一個IndexController和一個AdminController。

That description kind of raises a red flag to me. IF this was a really big project that needed to rely on high resusability and IF he coded such modules in a way that they could work independently of other modules in the the system and IF there was a need to isolate the admin area for each module, then this could be considered a reasonable approach.

那種描述給我帶來了一面紅旗。如果這是一個非常重要的項目,需要依賴高可重用性,並且如果他編寫這樣的模塊,他們可以獨立於系統中的其他模塊工作,並且需要隔離每個模塊的管理區域,那么這可以被認為是一種合理的方法。

But I would assume there's likely a dependency between Job and Product, in which case, this module approach sounds like over-engineering. Especially if there seems to be an arbitrary 'rule' being enforced (like one business object per module).

但我認為Job和Product之間可能存在依賴關系,在這種情況下,這種模塊方法聽起來像是過度工程化。特別是如果似乎有一個任意的“規則”被強制執行(就像每個模塊一個業務對象)。

Also, most MVC frameworks would assume that if you have Job and Product models, you have Job and Product controllers (not an IndexController for each entity). The purpose of modules is to segregate logical and presentational areas of your site, not divide up business logic.

此外,大多數MVC框架都會假設如果您有Job和Product模型,那么您有Job和Product控制器(而不是每個實體的IndexController)。模塊的目的是隔離站點的邏輯和表示區域,而不是划分業務邏輯。

While it's probably neither here nor there as far as proper MVC is concerned, it doesn't make sense to me to create a module that cannot operate fully independent from other modules.

雖然在適當的MVC方面它可能既不存在也不存在,但對我來說創建一個不能完全獨立於其他模塊運行的模塊是沒有意義的。

#4


2  

Q) When would you use Modules and when you would stick to Controllers?

問)你什么時候使用模塊,什么時候你會堅持使用控制器?

A) For me its all about the size of the application. When you have more than say 10 controllers you might want to think about refactoring some of them into a separate module. If you are planning on building a REALLY BIG application it may be worth spitting it up into modules before you start.

A)對我而言,關於應用程序的大小。當你有超過10個控制器時,你可能想要考慮將其中一些重構為一個單獨的模塊。如果您計划構建一個真正的BIG應用程序,那么在開始之前將其分配到模塊中可能是值得的。

Q) Whats your rule to decide Module or not Module ?

問)您的規則是什么決定模塊或不模塊?

A) Like I said having more than 10 controllers.

A)就像我說有超過10個控制器。

Q) What are the cons AND pros of my colleague's setup in your point of view?

問)在您的觀點中,我的同事設置的缺點和優點是什么?

A) If it is a small project he is over engineering it which will make it harder for other developers to jump into and will take him longer than needed to develop in the first place. He also runs the risk of confusing himself.

A)如果這是一個小項目,他就會過度設計,這將使其他開發人員更難以進入,並且他將花費更長的時間來開發所需的時間。他還冒着混淆自己的風險。

Q) What are the cons AND pros of my setup in your point of view?

問)在您的觀點中,我的設置的缺點和優點是什么?

A) My answer above pretty much covers it, if it's a smaller project your way will be quicker and less confusing in the long run. I prefer this approach and just re-factor if the scope is increased.

A)我上面的答案幾乎涵蓋了它,如果它是一個較小的項目,從長遠來看,你的方式會更快,更少混亂。我更喜歡這種方法,只是在范圍增加時重新考慮因素。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2010/08/25/7302e1487eef7302ad8171224b7761db.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com