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

[eluser]frist44[/eluser]
I'm trying to iterate through an object in a view. So my controller has:

Code:
$o = new Order();
        $o->get();
        $o->product->get();

In my view:

Code:
foreach ($obj as $order){
                echo '<tr>';
                echo '<td>' . $order->id . '</td>';
                echo '<td>' . $order->product->id . $order->product->finish . '</td>';
                echo '<td>' . $order->quantity . '</td>';
                echo '<td>' . $order->reconciled . '</td>';
                echo '<td>' . mysql_datetime_to_php($order->created) . '</td>';                
                echo '</tr>';
            }

But $order->product->id, doesn't show up. if I do :

foreach ($obj->product as $product), I can get the info out. Why isn't the deeper relationships passed through with the foreach variable?

Instead, it seems I have to dig through each one on the loop:

Code:
foreach ($obj as $order){
                $p = new Product();
                
                echo '<tr>';
                echo '<td>' . $order->id . '</td>';
                echo '<td>' . $p->get_by_id($order->product_id)->geometry . '-' . $p->get_by_id($order->product_id)->finish . '</td>';
                echo '<td>' . $order->quantity . '</td>';
                echo '<td>' . show_reconcile($order->reconciled) . '</td>';
                echo '<td class="textleft">' . mysql_datetime_to_php($order->created) . '</td>';                
                echo '</tr>';
            }

Controller:

Code:
$o = new Order();
        $o->get_iterated();
        $o->product->get();      
      
        $data['obj'] = $o;


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