I have one question. I want to tranfer object data from controller to the view. What way is better:
我有一个问题。我想把对象数据从控制器传输到视图。什么方法更好:
- Transfer a whole object to the view. And then inside view, get necessary data from object.
- 将整个对象传递到视图。然后在视图中,从对象中获取必要的数据。
- Inside controller get a necessary data from object and put this to the array. And transfer this array to the view.
- 在控制器内部,从对象中获取必要的数据并将其放到数组中。并将这个数组转移到视图中。
1 个解决方案
#1
1
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.
一致性是一种可取的属性。
#1
1
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.
一致性是一种可取的属性。