Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not sure what do you mean by VO. Is it value object?</p> <p>I'm a huge fan of the <a href="http://en.wikipedia.org/wiki/Domain-driven_design" rel="nofollow">DDD</a> (domain driven design) approach (though I don't consider my self as guru in it). In DDD you have so called <strong><em>Services</em></strong>. <strong><em>Service</em></strong> Is an action that operates on your domain and returns data. Service encapsulates the manipulation with you Domain data.</p> <p>Instead of having the controller to do all the domain logic like what items to retrieve, what DAO's to use and etc (why controller should care about the Domain anyway?), it should be encapsulated inside the Domain it self, in DDD case inside a Service.</p> <p>So for example you want to retrieve all the Category items of the category "electronics". You could write a controller that looks like this (forgive me if the code have invalid syntax, its for the sake of example):</p> <pre><code>public function showItemsByCategoryAction($categoryName) { $categoryId = $categoryDAO-&gt;findByName($categoryName); if(is_null($categoryId)) { //@TODO error } $itemIds = $categoryLinkDAO-&gt;getItemsByCategoryId($categoryId); if(empty($itemIds)) { //@TODO show error to the user } $items = $categoryItemDAO-&gt;findManyItems($itemIds); //@TODO parse, assign to view etc } </code></pre> <p>This introduces at least two problems:</p> <ol> <li>The controller is <a href="http://survivethedeepend.com/zendframeworkbook/en/1.0/the.model#zfbook.the.model.the.fat.stupid.ugly.controller" rel="nofollow">FSUC</a> (Fat stupid ugly controller)</li> <li>The code is not reusable. If you would like to add another presentation layer (like API for developers, mobile version of the website or etc), you would have to copy-paste the same code (expect the part of the view rendering), and eventually you will come to something that will encapsulate this code, and this is what Services are for.</li> </ol> <p>With the Services layer the same controller could look like</p> <pre><code>public function showItemsByCategoryAction($categoryName) { $service = new Item_CategoryName_Finder_Service(); $items = $service-&gt;find($categoryName); if(empty($items)){ //@TODO show empty page result, redirect or whatever } $this-&gt;getView()-&gt;bind('items', $items); } </code></pre> <p>The controller is now clean, small, and all the Domain logic is encapsulated inside a service that can be reused anywhere in the code.</p> <p>Now some people believe that the controller should know nothing about DAOs and communicate with the Domain only by using Services, other says that its ok to make calls to DAOs from the controller, there are no strict rules, decide what suits better for you.</p> <p>I hope this helps you! Good luck :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload