Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-04-2007, 09:09 AM
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-13-2007, 08:34 AM
Cristian's Avatar
Administrator
 
Join Date: Feb 2007
Location: Sibiu, Romania
Posts: 99
Default

You can't try to get into controller all results in one query ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-15-2007, 03:41 PM
Super Moderator
 
Join Date: May 2007
Location: netherlands
Posts: 2
Default

It's a common problem. You could do two things, one is to create a helper function in the model. Use custom row classes for this. So you can call getSpecs() on a row of the Product class. You're using the model itself for it, so you will need more code in your views.

I have written a blog post that deals with something similar: Naneau » Extra fields for Zend_Db_Table
check it out!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 01:13 PM.