From the course: Symfony 6 Essential Training

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Models in Symfony

Models in Symfony

- [Instructor] The M in MVC is for models. In Symfony, there are two pieces to the model puzzle. We briefly looked at entities but let's dive in a bit more. In Symfony, all the tools we need to manage our models are baked into the Doctrine object relationship mapper. Continuing with a demo project that Symfony provides, here is a post entity. It has an ID, a title, a slug, a summary, content, published at, comments, and tags. Comments and tags are interesting. We'll get back to those in a moment. When this entity was created, using the Symfony CLI tool, a corresponding repository was also created. Now, this repository is only used for finding and getting the entities. Saving an entity is a two-step process. Looking at the method new in our admin blog controller, we see on line 94, new starts up on 73. On line 94, using the entity manager, we persist and then on line 95 we flush. Persist tells the entity manager that this…

Contents