M
M
miy2016-06-30 12:12:46
symfony
miy, 2016-06-30 12:12:46

Using a database model in a view?

Good afternoon!
For example, we need to draw user data on the UI.
We call the repository method, which returns the User model with data to us.
Is it correct to pass the model itself to the view, or is it better to create a separate business object and map values ​​from the User model there? In fact, you get two identical objects, only one is a link to the base and the second is a business object.
Isn't it overkill?
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
shagguboy, 2016-06-30
@shagguboy

correctly transfer the model.
symfony.com/doc/current/book/templating.html
even do this in the dock.

T
ThunderCat, 2016-06-30
@ThunderCat

what is the fundamental difference? You just pass a reference to the object to the view, why create another object for the view separately? Only if it has property access logic that is more "convenient" for output. That is a helper. If there is such a need (there are a lot of properties and they are somehow cunningly formed and need preprocessing) - write a helper.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question