Skip to end of metadata
Go to start of metadata

Redirection Notice

This page will redirect to in about 2 seconds.


Working with Doctrine

Web applications often have to read and persist data from a database. In Symfony2, this can be done using any approach: using PDO, a custom framework or any approach we can come up with. Many developers are using Doctrine as Symfony2 provides good integration for it. Let's see what the Symfony2 Plugin has to offer when using Doctrine!


Doctrine makes heavy use of PHP Annotations to configure how an object maps to the database. The PHP Annotations plugin can be installed to get completion and navigation for PHP annotations.

Completion for Doctrine schema files

In Doctrine, we have several options for defining our mapping between classes and database and our database schema. We can use annotations, as well as define the schema in YAML file. The Symfony2 Plugin provides autocompletion when defining the schema in YAML.

Completion and Navigation for Entities and Repositories

In our application code, we can get repositories from Doctrine's object manager. PhpStorm provides completion (Ctrl+Space) for known repositories.

Once we have a repository to work with, the editor will know its type and provide completion (Ctrl+Space) for the specific repository, without requiring a PHPDoc type hint.

After fetching an entity from our repository, PhpStorm provides autocompletion for the entity as well.


The Symfony2 Plugin provides completion for entities in the ObjectManager's find() methods as well.

When hovering over an entity name, we can Ctrl+Click (or CMD+Click on Mac OS X) to navigate to its declaration. Ctrl+B (or CMD+B on Mac OS X) when the cursor is on the entity name works just as well.

Many developers create their own EntityRepository implementations. Whenever both an entity and repository implementation are found, PhpStorm will show a pop-up where we can pick the declaration to navigate to.

Completion for QueryBuilder

With the Doctrine QueryBuilder, we can create and execute queries on our object/relational model. PhpStorm comes with advanced tooling for working with databases, but those work on the database directly instead of on the model we've defined with Doctrine.

The Symfony2 Plugin fills that gap and provides completion for entities and their properties by analyzing the mappings that are defined.

Completion and Navigation for default Repositories

Doctrine comes with default repositories that provide several functions to query for data. There is find, which takes an identifier to look for. Functions like findBy, findAllBy and findOneBy, however, require us to specify the fields we want to search by. The Symfony2 Plugin provides completion support for these (Ctrl+Space).

Next to completion, navigation is provided too. We can hover over the field name and Ctrl+Click (or CMD+Click on Mac OS X) to navigate, or place the cursor on the field name and press Ctrl+B (or CMD+B on Mac OS X). Note that PhpStorm lets us choose the declaration to navigate to in case multiple are available.


  • No labels