There is a project in symfony that I want to remake using MVC. The project has controllers and twig templates, you only need to fasten the model. In which directory of the symfony project is it correct to create model files? Is there a tool in symfony that allows you to do this, instead of just creating these files and connecting them to the controllers?

    1 answer 1

    By default, symfony comes with ORM Doctrine 2, which uses Entities instead of Models. Entities are stored in the Entity directory inside the bundle. For example, src / Acme / AppBundle / Entity / Product.php.

    For more information, see the Databases and Doctrine documentation.

    The tool for creating them is:

    ./bin/console generate:doctrine:entity 

    (in fact, there are much more commands for working with entities, you can see the entire list by typing ./bin/console without parameters).

    It is not accepted to connect models to controllers, usually all work with models is carried out in services and repositories that are already being called inside the controller.

    • Isn't an entity part of the model? ;) - Dmitriy Simushev
    • Not. Models and entities - data representation in the form of OOP objects. The main difference is that Models can interact with the database (for example, you can always write $ model-> save () and the data will be saved to the database), and entities cannot work directly with the database, they only represent the object. Models are part of the ActiveRecord pattern, and entities are part of the DataMapper pattern. Here in more detail and with examples - habrahabr.ru/post/198450 - AlexDmitriev
    • The model (domain) has nothing to do with the database. At all. Entities (like repositories / value objects / aggregates, etc.) are terms of the domain model itself. At the same time, how exactly entities are displayed on the base (via ActiveRecord, DataMapper, TableGateway, or something else) is a slightly different story ... - Dmitriy Simushev
    • And instead of articles on the Habré, you need to read the classics: Fowler's PoEAA and Evans DDD - Dmitriy Simushev
    • In the "article on Habré" just described the patterns of Fowler. - AlexDmitriev