View Single Post
  #1 (permalink)  
Old 05-04-2007, 09:09 AM
zfuser zfuser is offline
Junior Member
 
Join Date: Apr 2007
Posts: 3
Default View without any business logic

I have some misunderstanding how can I get rid of any business logic in my view files. For example in controller i get list of products and in View I iterate through them with foreach:
PHP Code:
foreach($this->products as $row):
    print 
$row->productId;
    print 
$row->productsName;
endforeach; 
Problem occurs when i have to print related info about current product, for example product's specification. I can't this in one mysql select query, because there are many parameters in specification about one product, so I have to call Product model function in each product iteration:
PHP Code:
$product=new Product();
foreach(
$this->products as $row):
    print 
$row->productId;
    print 
$row->productsName;

    
$prodSpec=$product->getProductSpec($row->productId);
    foreach(
$prodSpec as $spec):
          
//print current product specification
    
endforeach;
endforeach; 
What is the best solution to this problem? Maybe I can in Controller make one large multidimensional array with all products and each product specification ($view->productsSpec), but it this case i have to iterate through product array two times - first in controller when i create $view->productsSpec array and second in view, where i iterate through $view->productsSpec.

Maybe there is some better solution to this problem?

Last edited by SpotSec : 05-04-2007 at 09:46 PM.
Reply With Quote