Welcome Guest, Not a member yet? Register   Sign In
DMZ object in foreach
#2

[eluser]slowgary[/eluser]
In your controller, you're assigning $data['obj'] = $o, so using a foreach() in your view is not necessary, since $obj is not an array. foreach() doesn't chop any of your data out, it just iterates through array elements, assigning their value to a temporary variable for you to display or make calculations on.

It looks like maybe you'd want to do something like this:
Code:
//controller
$o = new Order();
$o->get_iterated();
$o->product->get();

$data['order'] = $o;


//view
<td>&lt;?php echo $order->id; ?&gt;</td>
<td>
     <ul>
&lt;?php foreach($order->product as $product): ?&gt;
          <li>&lt;?php echo $product->name; ?&gt;</li>
&lt;?php endforeach; ?&gt;
     </ul>
</td>

I wouldn't recommend creating new Product objects in your view, especially if these make database calls. The general idea with MVC is that your controllers do that work.

I hope this helps.


Messages In This Thread
DMZ object in foreach - by El Forum - 09-04-2010, 07:45 AM
DMZ object in foreach - by El Forum - 09-05-2010, 08:16 AM
DMZ object in foreach - by El Forum - 09-05-2010, 09:05 AM
DMZ object in foreach - by El Forum - 09-05-2010, 09:22 AM
DMZ object in foreach - by El Forum - 09-05-2010, 09:35 AM



Theme © iAndrew 2016 - Forum software by © MyBB