Symfony2 and MVC model concept

I think that Symfony2 lacks the concept of ViewModel (e.g. ASP.NET MVC Framework), i.e. the model associated with the view. Symfony2 (as documentation) usually assigns an array to the view .

A view model may be a PHP class, but it is something different from a form model, and sometimes the same as a domain object. This is sometimes useful when working with a lot of information to display.

Anyway, is there any agreement on where presentation models should go in Symfony2? Any specific folder? To date, I have:

Symfony2/src/MyCompany/MyBundle/Form/Model

which contains models associated with forms. AND:

Symfony2/src/MyCompany/MyBundle/Entity

for domain objects (limited by database tables).

Suggestions are greatly appreciated. What about Symfony2/src/MyCompany/MyBundle/Model?

+3
source share
2 answers

There is no such thing as ViewModel in Symfony2. Your transition to entity or model templates directly. However, you can create your own ViewModel.

Entities are not models. As you said, these are doctrine-driven objects or domain objects. If you want to have business models, put them in MyBundle / Model, as many other packages do (like FOSUserBundle ).

0
source

No matter where you place it ViewModel... as long as your namespace reflects its location.

I would put it in src/MyCompany/MyBundle/View/Model, and then your namespace would be MyCompany\MyBundle\View\Model.

0
source

All Articles