IntelliJ IDEA 2022.2 Help

Routes

One of the cornerstones of developing a Symfony application is working with routes. The routing infrastructure ensures that we can use readable URLs (for example, /products/hammer instead of index.php?page=products&productid=12345) and that these URLs are mapped to a controller in our application that can respond to requests.

The Symfony Plugin provides several facilities for working with routes.

Install the required plugins

This functionality relies on the PHP, Symfony Support, and PHP Annotations plugins that should be installed and enabled in your IDE.

The plugins are available only in IntelliJ IDEA Ultimate.

  1. Press Ctrl+Alt+S to open the IDE settings and select Plugins.

  2. Switch to the Marketplace tab and use the search field to find the plugins.

  3. Click Install next to each plugin and restart the IDE if prompted.

Code completion for routes

IntelliJ IDEA provides code completion for functions that take a route name as an argument. In the editor, press Ctrl+Space to invoke code completion and do any of the following:

  • Specify arguments for such controller functions as generateUrl or forward.

    Symfony route name controller completion
  • Specify arguments for such Twig functions as path or controller.

    Symfony Twig completion

Since routes are linked to a controller, you can use Navigate to declaration Ctrl+B on a route to navigate to the corresponding controller. Alternatively, Ctrl+Click the service's name.

Navigate to Symfony controller

To navigate back to a route mapped to a controller, click the route icon the Symfony route icon in the editor gutter.

Navigate to Symfony route

Missing route inspection

Whenever you use the name of a route that is not defined or misspelled, IntelliJ IDEA displays the corresponding warning from the Missing Route inspection. .

the Missing Route Symfony inspection
Last modified: 29 November 2022