Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The scenario you are describing above seems like a good candidate for <a href="http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller" rel="nofollow">MVC</a>.</p> <p>In your case, I would create a class strictly for accessing the data (doing selects of product categories or specific products) and then have a different file (your view) take the output and display it.</p> <p>It could look something like this:</p> <pre><code>class Product_Model { public function find($prodId) { ... } public function fetchAll($category = '') { ... } public function search($string) { ... } } </code></pre> <p>Then somewhere else you can do:</p> <pre><code>$products = new Product_Model(); $list = $products-&gt;fetchAll(37); // get all from category 37 // in true MVC, you would have a view that you would assign the list to // $view-&gt;list = $list; foreach($ilst as $product) { echo "Product ID {$product['id']} - {$product['name']} - {$product['cost']}&lt;br /&gt;\n"; } </code></pre> <p>The basic principle of MVC is that you have model classes that are simply objects representing data from some data source (e.g. database). You might have a mapper that maps data from the database to and from your data objects. The controller would then fetch the data from your model classes, and send the information to the view, where the actual presentation is handled. Having view logic (html/javascript) in controllers is not desirable, and interacting directly with your data from the controller is the same.</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. This table or related slice is empty.
    1. VO
      singulars
      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