serek
serek

Reputation: 103

Symfony2 - data transmission to the view

I have one question. I want to tranfer object data from controller to the view. What way is better:

  1. Transfer a whole object to the view. And then inside view, get necessary data from object.
  2. Inside controller get a necessary data from object and put this to the array. And transfer this array to the view.

Upvotes: 0

Views: 43

Answers (1)

FyodorX
FyodorX

Reputation: 1480

The standard and, in my opinion, best way would be the first one.

Passing objects to the view allows you to use the same data structures across the entire application. If you have a Car model, for example, you may do something like this in a service:

$model = $car->getModel();

And in a view you would do something like this:

{{ car.model }}

Being consistent is a desirable attribute.

Upvotes: 1

Related Questions