Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP: 5 layer model
    primarykey
    data
    text
    <p>I have question about how to "correctly" write my application.</p> <p>I would like to follow the service/DAO/mapper/entity model and I think that I fully understand it but I found out that some things which I want to do might collide with general conception of this model.</p> <p>I have these database tables: <img src="https://i.stack.imgur.com/n8ugl.png" alt="Product table and it&#39;s related table - manufacturers"></p> <p>I have simple ProductDbMapper which gets product's data from database and returns them as a Product entity so I can use it like this:</p> <pre><code>echo $productEntity-&gt;getName(); $productEntity-&gt;setPrice(29.9); </code></pre> <p>I think that it would be great to be able to use somethink like this:</p> <pre><code>echo $productEntity-&gt;getManufacturer()-&gt;getName(); </code></pre> <p>The "getManufacturer()" method would simply query another service/DAO for the manufacturer by id. I know that the correct way how to get manufacturer of a product is:</p> <pre><code>$product = $productService-&gt;getProduct(5); $manufacturer = $manufacturerService-&gt;getManufacturerByProduct($product); </code></pre> <p>But I think that "the fluent" solution is much simplier - it's easy to understand and fun to use. Actually it's pretty natural. I tried to implement this by callbacks. I passed the callback which calls manufacturer's service to Product entity in my ProductMapper.</p> <p>Problem is that it looks like I'm trying to follow the 5 layer model and at the same time I'm trying to avoid it. So my question is: does this look like a good solution? Does it make sense? How could I achieve the same (magic) in better way?</p>
    singulars
    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.
 

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