Book Image

Symfony2 Essentials

Book Image

Symfony2 Essentials

Overview of this book

Table of Contents (17 chapters)
Symfony2 Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Entities – the Model layer


Finally, we need to dive into the Model layer of Symfony2 framework. Symfony2 heavily relies on Doctrine2. Doctrine2 is one of the most popular object-relational mapping libraries. While there are alternatives like Propel, in many cases most of the third-party bundles support only Doctrine2.

To create a database model, we need to properly connect to the database first. Make sure that the properties.yml file contains the correct values, and you are able to connect to your database.

Note

Note that in the production mode, each change within the YAML file requires the cache to be cleared, otherwise, it will not be noticed. In the development mode, the configuration is recreated without this requirement.

Now, we need to create our first entity file. In case of entities, we will use annotation as this seems the easiest way to handle database changes and migrations. This will also make it easier for us to make changes in the future and add other stuff related to entity-like...