There are 2 tables - customers and orders. One connection to many. How in one view to bring information about the client from the model "clients", and below the list of all his orders using the model "orders"? I read that something like this is realized through the widget, is it correct? And how to implement it?

  • You pass in the view a model that has a relation, here and refer to it. How to do it, handles through someone's widget or something else, depends only on your imagination and requirements - Ninazu

1 answer 1

In your controller you get a client model:

$client = ClientActiveRecord::findById($_GET['client_id']); 

Pass this $ client to the view.

And in the view after the output of customer information write like this:

 foreach($client->getOrders() as $order) { // вызываете под вьюшку для заказа либо var_dump($order); } 

Or call the samopisny widget:

 OrdersWidget::run($client->getOrders()); 

There are lots of options.