title: Zend Framework: Using controller method in view to call model method
body: <p>I've got a little problem here. I have category_id for every product in DB. I also have a category table in DB for categories and their ID. Now i need to put in into view together. I've made add, edit and delete action, also show action, where is category showed with the rest of product description. But now I have a problem with an index action. </p>
  
  <p>In show I did this: </p>
  
  <pre><code>public function getProductTable()
   {
      if (!$this-&gt;productTable) {
           $sm = $this-&gt;getServiceLocator();
           $this-&gt;productTable = $sm-&gt;get('Product\Model\ProductTable');
       }
       return $this-&gt;productTable;
   }
  
  public function getCategoryTable() {
      if(!$this-&gt;categoryTable){
          $this-&gt;categoryTable = $this-&gt;getServiceLocator()
              -&gt;get('Product\Model\CategoryTable');
      }
      return $this-&gt;categoryTable;
  }
  
   public function showAction()
   {
      $id = (int) $this-&gt;params()-&gt;fromRoute('id', 0);
      if (!$id) {
           return $this-&gt;redirect()-&gt;toRoute('product', array(
               'action' =&gt; 'add'
           ));
      }
  
      try {
           $product = $this-&gt;getProductTable()-&gt;getProduct($id);
           $category = $this-&gt;getCategoryTable()-&gt;getCategory($product-&gt;category_id);
       }
       catch (\Exception $ex) {
  
           return $this-&gt;redirect()-&gt;toRoute('product', array(
               'action' =&gt; 'index'
           ));
       }
  </code></pre>
  
  <p>It's easy, cause during the show action I will get one result from DB, so I know exactly what category_id product has. </p>
  
  <p>But, in index.html I will get all the products from DB and need to iterate them throughout Foreach. That's the place where I need to get a call </p>
  
  <pre><code>$this-&gt;getCategoryTable()-&gt;getCategory($id);
  </code></pre>
  
  <p>Since this is a controller method using the sm to use the model method, how should I use this in my index.html view to get the exact category name for every product?</p>