This tutorial has a new version, check it out!

Code goes in src/ and app/

You may have noticed that most of the committed files were in app/ and src/. That's on purpose: these are the only two directories you need to worry about. src/ will hold all the PHP classes you create and app/ will hold everything else: mostly configuration and template files. Ignore all the other directories for now and just focus on src/ and app/.

Building the First Page

Remember the functional homepage? It's coming from this DefaultController.php file. Delete that! Do it! Now we have an absolutely empty project. Refresh the homepage!

No route found for "GET /"

Perfect! That's Symfony's way of saying "Yo! There's no page here."

Now back to the main event: building a real page.

Our top secret project is called AquaNote: a research database for Aquanauts. These cool underwater explorers log their discoveries of different sea creatures to this nautical site. Our first page will show details about a specific genus, for example, the octopus genus.

Creating a page in Symfony - or any modern framework - is two steps: a route and a controller. The route is a bit of configuration that says what the URL is. The controller is a function that builds that page.


So, step 1: create a route! Actually, we're going to start with step 2: you'll see why. Create a new class in AppBundle/Controller called GenusController. But wait! The namespace box is empty. That's ok, but PhpStorm can help us out a bit more. Hit escape and then right-click on src and select "mark directory as sources root".

Now re-create GenusController. This time it fills in the namespace for me:

namespace AppBundle\Controller;
... lines 4 - 7
class GenusController
... lines 10 - 16

Go Deeper!

If namespaces are new to you, welcome! Take a break and watch our PHP Namespaces Tutorial.

The most important thing is that the namespace must match the directory structure. If it doesn't, Symfony won't be able to find the class. By setting the sources root, PhpStorm is able to guess the namespace. And that saves us precious time.

Controller and Route

Inside, add a public function showAction():

... lines 1 - 7
class GenusController
... lines 10 - 12
public function showAction()
... line 15

Hey, this is the controller - the function that will (eventually) build the page - and its name isn't important. To create the route, we'll use annotations: a comment that is parsed as configuration. Start with /** and add @Route. Be sure to let PhpStorm autocomplete that from the FrameworkExtraBundle by hitting tab. This is important: it added a use statement at the top of the class that we need. Finish this by adding "/genus":

... lines 1 - 4
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
... lines 6 - 7
class GenusController
* @Route("/genus")
public function showAction()
... lines 14 - 16

Beautiful, that's the route and the URL for the page is /genus.

Returning a Response

As I already said: the controller is the function right below this, and its job is to build the page. The only rule for a controller is that it must return a Symfony Response object.

But hold on. Let's just all remember what our only job is as web developers: to understand the incoming request and send back a response, whether that's an HTML response, a JSON response of a PDF file. Symfony is modeled around this idea.

Keep things simple: return new Response. The Response class is the one from the HttpFoundation component. Hit tab to auto-complete it. This adds the use statement on top that we need. For the content, how about: 'Under the Sea!':

... lines 1 - 5
use Symfony\Component\HttpFoundation\Response;
class GenusController
* @Route("/genus")
public function showAction()
return new Response('Under the sea!');

That's it!

We've only created one file with one function, but we already have a route, a controller and a lot of sea floor that needs discovering!

If you refresh the homepage, well... that's not going to work. Navigate instead to the URL: /genus. Woh! There's your first page in Symfony, done in about 10 lines of code. Simple enough for you?

Next, let's create a dynamic URL.

Leave a comment!

  • 2018-07-09 Victor Bocharsky

    Hey Aika,

    Probably you're not in dev mode. What URL do you have in the address bar? Keep in mind, you need to point document root of your Xamp server to the web/ directory, otherwise you'll need to specify it in the URL like: http://localhost/web/app_dev.php


  • 2018-07-07 Aika Sat

    hello! I'm using xamp server and still getting an error 404 (not the beautiful symphony one) I've also tried adding app_dev.php

  • 2017-12-25 Victor Bocharsky

    Hey Hike,

    Glad you got it working. Keep in mind you always can look over logs in production to see what's wrong with the next command:
    tail -f var/logs/prod.log


  • 2017-12-25 Hike Nalbandyan

    actually nvm. I found the reason.
    THANKS A LOT you're very helpful

  • 2017-12-25 Hike Nalbandyan

    Tnx Victor.

    I do have this other small problem.

    the {{ dump() }} function works great in dev but in prod I get "500 Internal Server Error", and yes, I cleared the cache :D. I wonder why...

    I don't have to fix this but I'm trying to figure out symfony, so I'd appreciate the help.

  • 2017-12-25 Victor Bocharsky

    Great! Then that was the answer, you need always to clear the cache for any change in configuration, routes, translations, tempaltes, etc. The exception is only for PHP code, but that's not always the rule. So always clear the cache if you want to check things in prod, especially if you have some weird errors like this, which works for dev mode.

    Also, if you use a real web server like Nginx or Apache - it may depend on your Nginx / Apache configuration, but looks like this's not related to the problem in your case.


  • 2017-12-25 Hike Nalbandyan

    Yeah, clearing the cache did the job for me tnx a lot.
    Im using Nginx+Apache

  • 2017-12-25 Victor Bocharsky

    Hey Hike,

    Symfony cache is not rebuilt in prod mode for performance and security reasons, that means you need manually clear it with:
    bin/console cache:clear --env=prod

    But in dev mode, when you perform some changes, cache is automatically rebuilt for convenience

    Try to clear the prod cache with the command I mentioned and try to reach that URL again: http://stm3.tst/app.php/genus

    Also, do you use PHP build in web server (bin/console server:run) or do you configure a real web server like Nginx or Apache? :)


  • 2017-12-25 Hike Nalbandyan

    thanks for the reply.
    actually, stm3.tst/genus/ => stm3.tst/app.php/genus (NOT working)
    stm3.tst/app_dev/genus (Works just fine)..
    still, have no idea why. I'll be glad if you could explain it

  • 2017-12-25 Victor Bocharsky

    Hey Hike,

    See my answer above: - I bet you just have a trailing slash problem... or prod cache problem ;)


  • 2017-12-25 Victor Bocharsky

    Hey Hike,

    Good debugging with "bin/console debug:router"! Actually, looks like you had found an answer but didn't notice it :) As it's said:
    genusController ANY ANY ANY /genus but I see you're trying to reach http://stm3.tst/genus/ URI, i.e. you add an extra slash "/" in the end, try to request "http://stm3.tst/genus" instead. Remember, that "/genus/" and "/genus" are 2 different URLs for Symfony Router ;)

    P.S. Here's a nice trick how to avoid errors with trailing slash:

    P.P.S. Also don't forget to clear the prod cache when you add or edit routes.


  • 2017-12-22 Hike Nalbandyan

    Well I managed to access that route by adding the app_dev.php to my url.
    Why did this fix it for me? will it be like this in prod? that is weird

  • 2017-12-22 Hike Nalbandyan

    Hi .
    I followed this and did exactly as it says in the video (symfony 3.4.2)

    I managed to get it running at sym3.tst/ , but when i go to stm3.tst/genus/ I'm getting this:
    "Oops! An Error Occurred
    The server returned a "404 Not Found".
    Something is broken. Please let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused".

    I thought that the route is not created' but when i do 'php bin/console debug:router' I get this:
    genusController ANY ANY ANY /genus

    Have no idea what's wrong.. HELP pls

  • 2017-10-31 Victor Bocharsky

    Hey bro,

    We use PhpStorm IDE! We think it's the best IDE for developing PHP applications and it helps a lot when you work with Symfony Framework - see Symfony plugin. Btw, we even have a FREE course about it, check it out:


  • 2017-10-31 Khalil Bajwa

    bro which tool you use to write code.

  • 2017-09-14 Victor Bocharsky

    Ah, legacy project, then it makes sense. Yes, that link to Symfony docs I mentioned could be really helpful in your case, so try to figure it out first. And if you still have questions after, please, ask.


  • 2017-09-14 Name

    Sure, thanks again man, you have been really helpful. I will see what I can do. I am actually building the nginx conf for an existing installation. It has its admin part created using symfony with its web only folder here `/public_html/web/app.php` . It has its website part to the public in this path `/public_html/index.php` which accesses the symfony admin database ...... I am using nginx conf with two `location` paths having a `root` part in each, one for app.php and the other for any .php .....

  • 2017-09-14 Victor Bocharsky

    Hey Name,

    It's difficult to understand your case, if we're talking about production, why do you have 2 front controllers: index.php and app.php? Anyway, check out the docs: - there's an example how to configure a few front controllers at once.


  • 2017-09-13 Name

    thanks Victor, it did help. Also can I get nginx config help for say I have all the PHP in `/public_html/index.php` and the web is in `/public_htm/web/app.php`How to server the index.php . the server is redirecting me always to `localhost/login` which serves app.php

  • 2017-09-13 Victor Bocharsky

    Hey Name,

    If you're talking about prod environment, you probably need to clear and warm up the cache with:
    $ bin/console cache:clear --no-warmup --env=prod
    $ bin/console cache:warmup --env=prod

    For dev - try to do the same but "--env=dev" instead.

    Let us know if it doesn't help you.


  • 2017-09-13 Name

    For some reason updating the route doesn't reflect using the nginx server

  • 2017-07-26 Diego Aguiar

    Hey tyaak

    I use PHPstorm and it requires "Symfony" and "PHP Annotations" plugins, I believe you would need something similar

  • 2017-07-26 tyaak

    I am using NetBeans 8.2 with PHP and symfony on ubuntu 16.04. I filled in the namespace automatically, but I can't get the "@Route()" to autofill. "Route" doesn't show up under suggestions for "@". Am I missing a plugin or something? I already have PHP enhancements.


  • 2017-07-26 Diego Aguiar

    You are very welcome Ben :)

  • 2017-07-25 Ben

    Thank you Diego for explaining this, I wish it was said in the video as I really scratched my head on this one.

  • 2017-07-25 Diego Aguiar

    Hey Ben

    Each belongs to a different components, The Sensio one, allows you to define and use Symfony routes via annotations, so it's like a bridge


  • 2017-07-25 Ben

    I use Netbeans and it adds this:
    use Symfony\Component\HttpFoundation\Response;
    use Symfony\Component\Routing\Route;

    Could you please tell me what is the difference between your Sensio path and the symfony one please? Thanks

  • 2017-07-12 Marco Koopman

    That fixed it! Thanks :)

  • 2017-07-11 Diego Aguiar

    Hey Marco Koopman

    Look's like you are using the incorrect Reponse object, you should use "Symfony\Component\HttpFoundation\Response" instead
    When you use autocomplete, be careful which type it's autocompleting


  • 2017-07-10 Marco Koopman


    The controller must return a response (Object(Symfony\Component\BrowserKit\Response) given).


    class GenusController
    * @Route("/genus")
    public function showAction()

    return new Response('yo');



    please help :)

  • 2017-06-22 El_J


  • 2017-06-22 Victor Bocharsky

    Hey El_J ,

    This is PhpStorm IDE with Darcula theme! With Symfony Plugin that's our favorite IDE :) We even have a screencast about it: - where we explain how to properly configure it to work with Symfony apps.


  • 2017-06-21 El_J

    What IDE is it?

  • 2017-06-12 Victor Bocharsky

    Hey Sean,

    Great, actually it means you're on the right way! Now go to the "web/app_dev.php" file and temporarily comment out the security check . Then refresh the page and you'll have access to get this page. Doing so isn't secure, but it's OK for your local host. But probably you need to invent more clever solution for your case, for example try to "dump($_SERVER['REMOTE_ADDR'])" to see what remote IP you you have and allow access from that IP.


  • 2017-06-09 Sean M

    I looked at the more info section you referenced. But when I tried adding app_dev.php (i.e., I get "You are not allowed to access this file. Check app_dev.php for more information."


  • 2017-05-23 Victor Bocharsky

    Hey Mehdi,

    Hm, still it's weird for me. Probably the problem might be in the library you use for modifying HTML code when populate 2nd and 3rd selects. How do you modify them? With some library like jQuery? Or do you use a JS framework for it, like Angular? If those fields are not disabled, then probably they don't have name attribute - fields without name attribute do not send to the server. Please, double check names of those fields after modifying them. Try to "dump($_POST); die;" somewhere in the beginning of your action - do you see those fields in the dumped result?


  • 2017-05-22 Mehdi Bagheri

    Hi Victor,
    Thanks for the reply. I think I didn't explain clearly. sorry for that.
    the process is like this:
    1. I select an option form first select .
    2. the options in the second select field are populated according to the option selected in the first step (using ajax call)
    3. I select an option from the second select
    4. the options in the third select are populated according to the option selected in the previous step (using ajax call)
    5. I select an option from the third select
    6. I hit the submit button

    The form has no action attribute so it sends POST data to the same page. The problem is that I only get the option selected in the first select in the POST variable. The select fields are not disabled.

  • 2017-05-22 Victor Bocharsky

    Hey Mehdi,

    It's weird that data doesn't send to the server. Do you send the whole form with populated 2nd and 3rd lists with AJAX request? Or does it send without AJAX? Please, also ensure those fields aren't disabled - it might be the key why they do not send to the server.


  • 2017-05-22 Mehdi Bagheri

    Hi Ryan
    I'm following your symfony tutorials. They are great. thanks for that.
    I have a problem while working with forms. I have a form with 3 selects. the options of second select depend on the selected option of first and the options of the third one depend on the selected option of second select. I use symfony form types to render the form and then I use ajax to populate the options of second and third selects. however, after doing so, the values of these two selects are not sent with POST variable when I submit the form.
    Do you have any idea why this happens?

  • 2017-05-06 Victor Bocharsky

    Hey Christian,

    Yes, PhpStorm is paid, but it has a free early access program: https://confluence.jetbrain... which could be interesting for you.


  • 2017-05-06 Christian Neil Anthony Wico

    This is gonna be a bummer if you can't get your hands on PHP Storms as it is a paid app. No extensions available in VS Code for Symfony...

  • 2017-03-04 weaverryan

    Yo Blaise!

    I think you're doing *almost* everything right. First, right now, we want to boot Symfony in the dev environment. That means either setting your Nginx conf to use app_dev.php as the default script, OR, just putting this in your URL - e.g. URLs (locally) like this:


    One way or another, you want your web server to execute the web/app_dev.php file. If you do this, even if you see an error or a 404 page, it should be a big, beautiful debugging error page (versus the simple, ugly 500 Internal Server Error you're seeing now). So, let's get this working as step 1!

    When you actually deploy, you *do* want to set your configuration to execute app.php. The only caveat is that whenever you switch to the "prod" environment (this is the "environment" used when you execute the app.php file), you need to clear your prod cache via:

    php bin/console cache:clear --env=prod

    This is obviously an important detail! So we talk about it in the next tutorial - and the next 2 chapters after that. My guess is that it's working in production now because when you deployed your code, the cache directory was empty, so Symfony correctly built new cache files on production from the latest versions of your files. But locally, as soon as you execute your app in the "prod" environment the first time, it creates a bunch of cache files. If you change something (e.g. delete DefaultController), then it's still using that old, now-outdated cache. Behind the scenes, the cached route still exists, but since the controller was deleted - you're getting a 500 error. Oh, and one last thing - you can always see what the error was in the prod environment by looking at the var/logs/prod.log file.

    Let me know if that helps!

  • 2017-03-03 Blaise

    Hey. I've got this problem:
    I am using external server on Linux with NGINX running.
    As long as symfony DefaultController is on server routing only works for "/" as set to default. When i delete it, i get

    Oops! An Error Occurred

    The server returned a "500 Internal Server Error".

    Something is broken. Please let us know what you were doing when this error occurred.
    We will fix it as soon as possible. Sorry for any inconvenience caused.
    When i do everything step by step via tutorial i get 404 not found. Tried /app.php/~~ tried app_dev.php - does not work.
    NGINX conf file is set from symfony documentation.
    Deployment is set and works.
    What the fudge is going on? :)

  • 2017-01-06 Victor Bocharsky

    Hey Marlene,

    Not `composer update` but `composer install`. You could check the README file inside downloaded code - there's instructions how to bootstrap project. Let us know if `composer install` doesn't help you.


  • 2017-01-05 disqus_L54JZwZGNQ

    I had to go into Terminal and run composer update????????

  • 2017-01-05 weaverryan

    Hey Marlene!

    Dang, sorry about that - not having auto-complete takes all the fun out of it! A few questions:

    1) When you type @Route, are you using a capital R - it'll only auto-complete if you are!
    2) If you ignore the fact that it doesn't auto-complete and manually add the @Route (and manually add the use statement at the top of the class - use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route) - does the page work? I'm trying to make sure something else isn't going wrong.

    If you ARE using a capital R and the page works when you setup things correctly... but still don't get auto-complete, you may need to check with the PhpStorm guys - I've never seen this specifically not work!

    Good luck!

  • 2017-01-05 disqus_L54JZwZGNQ

    Using the latest PhpStorm 2016.3.2. Have enabled, installed and reinstalled Symfony and PHP Annotations, restarted, invalidated cache, etc. I still cannot get @route to autocomplete. When I go to Settings>Editor>Inspections I see "Symfony | Route | Symfony: Route settings deprecated" I have googled but nothing. Help! Also this message in PHPAnnotations: Doc block annotation class found, but its missing in use statement You should import the class as use statement

  • 2016-12-21 weaverryan

    Hi Lazar Aleksic!

    Hmm. so, as you can see in the video, when you type @Route - and let it auto-complete, it should add the use statement on top. If it didn't, double-check that you installed the "PHP Annotations" PHPStorm plugin. I forgot to show this in the screencast (but we did add a note later about it).

    Let me know if that helps!

  • 2016-12-21 Lazar Aleksic

    Hi there i have a problem.

    I typed : /**
    * @Route("/Genus")
    and it didnt set the USE sensio. I still see that my Route(genus) didnt became Green as it shd.

  • 2016-12-05 Victor Bocharsky

    Hey Sebastian,

    Actually, we do teach how to do a login form, but in another course. This topic is pretty complex to cover it in this intro tutorial. Please, check our Symfony Security: Beautiful Authentication, Powerful Authorization course.


  • 2016-12-02 weaverryan

    Hey Sebastian Torres!

    This is a classic problem / challenge we have with the Symfony documentation: there are so many different and valid ways to do things, that sometimes one topic can become disjointed. I recommend checkout out our security tutorial - - we build a traditional login form that loads users from the database. The whole setup is there (it's a bit of a different approach than in the Symfony docs - one that I slightly prefer).

    Cheers and good luck!

  • 2016-12-01 Sebastian Torres

    When i was seeing

    How to Build a Traditional Login Form

    i was hoping that I would create a login form using database but when I see "In this entry, you'll build a traditional login form. Of course, when the user logs in, you can load your users from anywhere - like the database. See B) Configuring how Users are Loaded for details". It was the beginner of the confusion. I followed those steps. but I could not to do the login form. I have been trying to understand the documentation of symfony

  • 2016-12-01 Sebastian Torres

    Why don't you teach how to do a login form. You said in this videos that we know about 50% . why don't you teach how to do a login ? how to create. I mean the documentation about symfony is very confuse, i was trying do design an app with a simple login form but when i see that i see
    "you need to design a form with database click here. Before to read this topic you need to have an entity. see FosUserBundle . After see ForUserBundle i see put your own logic here with the correct parameters. I come back to the symfony.
    class: AppBundle:User
    property: username"
    our_db_provider is for what i do not understand.


  • 2016-11-09 Victor Bocharsky

    Hey Megakills ,

    What do you mean about the "controller map"? i.e. PhpStorm also removes annotation routes? I think this magic could come with Symfony plugin, but I'm not sure. Probably, I have never encountered with this problem because of keeping this controller or just rename it in some cases :p


  • 2016-11-08 Megakills

    When i delete DefaultController.php phpstorm also delelte the controller map.

  • 2016-11-08 Victor Bocharsky

    Hi Jelle,

    Quick catch! ;)


  • 2016-11-08 Jelle Schouwstra

    Sorry, forgot to add the double quotes around "/genus" !

  • 2016-11-08 Jelle Schouwstra

    First off, great tutorial!

    When I added the annotation /genus and I tried to access it I get the following error:

    [Syntax Error] Expected PlainValue, got '/' at position 7
    in method AppBundle\Controller\GenusController::showAction() in
    C:\inetpub\wwwroot\aqua_note\src\AppBundle/Controller/ (which is being
    imported from "C:\inetpub\wwwroot\aqua_note\app/config\routing.yml").

    500 Internal Server Error - FileLoaderLoadException

    This is my controller code:
    namespace AppBundle\Controller;

    use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
    use Symfony\Component\HttpFoundation\Response;

    class GenusController
    * @Route(/genus)
    public function showAction(){
    return new Response('Under the sea!');

  • 2016-09-25 weaverryan

    Hey Mamun!

    I think I know the problem :). Whatever the URL is in your browser - add an app_dev.php to it. For example, if you setup XAMPP to have a URL like http://symfony.l, then go to http://symfony.l/app_dev.php. In fact, while developing, you'll always have that app_dev.php in your URL - e.g. http://symfony.l/app_dev.php/products (instead of just /products).

    Having the app_dev.php in the URL loads Symfony in the "dev" environment, where you see any errors and your cache is always rebuilt. The reason you don't see this in the video is that we're using the built-in PHP web server through Symfony, which does this (automatically & invisibly) for you. But, if you're using your own web server, that's great - you just need to add that app_dev.php to the URL yourself. When you do that, I think you won't see this error anymore. There's more info about this here:

    Let me know if that helps!

  • 2016-09-25 Mamun

    After deleting DefaultController.php, I got 500 Internal server error.

    Here is the message": Oops! An Error Occurred

    The server returned a "500 Internal Server Error".

    Something is broken. Please let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused."

    I'm using widows 10, PHP version: 5.6.24, Symfony 3 . As PHP server I'm using XAMPP.

    What could be the reason for this error?

  • 2016-09-19 weaverryan

    Hey Leon!

    Hmmm. I'm sure we can figure this out! A few questions:

    1) Did you run the bin/console server:run to start the built-in web server? Or did you configure a web server to point to your project?
    2) What is the URL in your browser?
    3) Is the 404 error a "pretty" error that's coming from Symfony, or is it much more plain?

    Let me know and we'll find the problem :).


  • 2016-09-16 Leon Hitzer

    I Symfony just install and so far everything runs. I followed your video but unfortunately get in the browser the message: The server returned a "404 Not Found".

  • 2016-09-07 Victor Bocharsky

    +1 It makes sense to clear the cache. Also ensure that the "Power Save Mode" is off: "File" -> uncheck "Power Save Mode".

  • 2016-09-07 PlayIt

    I had the same problem, I did two things, I believe the latter fixed it.
    Uninstalled plugin / restart /reinstalled plugin / restart..
    Still didn't work.
    File -> Invalidate Caches / Restart
    Wait for indices to finish building on restart ( takes a min )

  • 2016-08-25 Victor Bocharsky

    Hm, I think internal server error is not so bad here. I suppose your server configured properly, you just don't clear prod cache. Symfony recompile cache for changed files by itself in dev mode, but in prod mode you should clear it manually each time you make any changes. So try to clear cache for prod with the next Symfony console command:

    $ bin/console clear:cache --env prod

    Or just manually remove "/path-to-your-symfony-app-root-dir/var/prod" folder, it should help you. Let me know if you still has this error after clearing the prod cache.


  • 2016-08-23 Kaiser

    Thanks for quick response. :)

    The root directory is now /web.
    When launching the app.php (which correctly is set as directory index i .htaccess) i get the "500 internal..." error. but app_dev.php works fine (though it has the debug bottom bar).

    If I'm running the application without MAMP, but just starting the server through terminal, i get another 500-error stating "An error occurred while loading the web debug toolbar (500: Internal Server Error)"
    This occurs both through app.php and app_dev.php?

    I am pretty new to all serber & system settings as well as managing bigger projects. I was used to just fire up MAMP, and build the directory structure myself without frameworks. So I am not sure at all how to follow the guide "Configuring a Web server" as in where those settings should be applied etc..

  • 2016-08-23 Victor Bocharsky

    Hey Kaiser,

    Yes, you should set the "/web" directory as a document root for Symfony projects.
    Also make the "web/app.php" as a directory index file. This actually set up in "/web/.htaccess" already, but your server could ignore it, depends on server configuration.

    BTW, the correct example of configuring a virtual host for Symfony project you could find here: Configuring a Web Server. There're few examples for both Apache and Nginx web servers.


  • 2016-08-22 Kaiser

    First of all these tutorials are great! Thank you so much for making them!
    However. I can't seem to get this default routing working.

    I'm on mac El Capitan
    PHPstorm 2016.2
    Symfony 3.1.2

    I've set up MAMP to my projects directory as document root, but when typing localhost:8000 i just get a list of files in th edirectory.
    When typing localhost:8000/web
    or localhost:8000/web/app_dev.php
    it loads the "Welcome to symfony" page.

    Without the defaultController. i get the right result with localhost:8000/web/app_dev.php
    and with localhost:8000/web i get a basic "500 internal server error". ?

  • 2016-08-16 Vlad

    Thank you, Ryan!

  • 2016-08-15 weaverryan

    Yo Vlad!

    There is a proper way to do this - with $this->forward(). But - by design - this creates a sub-request in the system, so there is some performance impact for doing this (you can look in the Performance tab in the Profiler for this page - you'll see exactly what I mean and how much of an impact there is). Otherwise, yes, you could instantiate the controller directly (and call setContainer() on it) - it is just an object, of course. But, there's some risk in this, because certain normal pre-controller hooks won't fire, so you could rely on some functionality there that suddenly doesn't work. The longer, more proper answer is that if you need to call something, you should extract it to a service and call that service.

    But there you go - there's the long answer, because I know you'll find it interesting anyways!


  • 2016-08-12 Vlad

    If I want to call a controller action inside of another controller, is there a proper way of doing it (via routes, etc.), or do I simply instantiate the target controller and call it's function directly?

  • 2016-07-16 nickmarinho

    Sorry, the error was mine. I'm new in this symfony world. Learning well with this tutorial. Thanks a lot;

  • 2016-07-16 weaverryan

    Hey Luciano!

    Everything should still work just fine in 3.1.2 - what problems are you having? Do you have a "Route Not Found" error? What URL are you going to?


  • 2016-07-15 nickmarinho

    I'm trying this with symfony 3.1.2 but this chapter does not work.....the router not work =(

  • 2016-05-25 weaverryan


  • 2016-05-25 Mike

    I fixed my problem. I am using Sourcetree to push my changes but it is not updating my remote server. I had to us the CLI to pull my changes

  • 2016-05-24 Mike

    I deleted the DefaultController and it still loads the welcome to symfony page. Why is this? Also, when I create the genus route it says no route found. I'm using a remote server instead of my local pc. The symfony project is located in this directory /var/www/html/my_project

  • 2016-05-02 weaverryan

    Cheers! Yes, bin/console cache-clear --env=prod is your friend for the prod environment :)

  • 2016-05-02 Yoni L.

    Thank you for this great tutorial! just to share I had some trouble with an error 500 with /genus route. That was due to the cache in /app/cache/prod.

  • 2016-04-27 Konrad Zając

    Yes, thanks!

  • 2016-04-27 weaverryan

    Hi Konrad!

    I don't understand your question - can you ask it again? Which folder are you talking about? Are you talking about creating an empty project in PHPStorm? If so, I usually create my project with the Symfony installer. Then, in PHP storm, I go to "File -> Open Directory" and choose the directory that was just created. This "makes" a new project in PHPStorm, using that directory. I hope I answered your question :).


  • 2016-04-26 Konrad Zając

    Create an empty project or a PHP empty project and load that folder created with the command line?

  • 2016-04-26 weaverryan

    Hi Josh!

    Yea, unfortunately we use "controller" interchangeably to refer to *both* the class, and the individual methods in the class (sometimes the individual methods are sometimes called "actions"). When I say "controller", I am typically referring to the single method that returns the Response object. When I'm talking about the class, I'll usually say "controller class". I can totally see how that can cross some wires :)


  • 2016-04-26 weaverryan

    I do! Install the "PHP Annotations" plugin for PHPStorm - this gives PHPStorm intelligence about how annotations and use statements work. You'll also start to get awesome auto-complete when you use annotations.


  • 2016-04-25 Emilien Ramos

    I'm sorry but I don't have the @Route completion ...

    I have the others (Response, ...) and the "use Sensio\Bundle\...\Route" message is highlighted with the note : "Usage of statement use was not found"

    Do you know why ?

  • 2016-04-25 Emilien Ramos

    Thanks ! :)

  • 2016-04-25 Josh Hardman

    Hey weaverryan,

    Thanks for your quick response! Your explanation does help. In my experience the controller has referred to the entire class, which has various methods that handles business logic, along with a display function that passes variables on to the template. In Symfony, is the controller simply the single method associated with the matched route which returns a response object? I'm sure this will all make better sense as I keep working through the videos!

  • 2016-04-24 weaverryan

    Hi Josh!

    It's actually the internal a of Symfony that call showAction. Here's what happens:

    1) the user loads the page - Symfony boots up

    2) Synfony reads the routing info (the @Route annotation) to determine which route matches the current URL

    3) Symfony calls the method associated with the matched route (called the controller) so that we can build the page.

    Does that help? It's a good question - understanding this flow is a crucial step!


  • 2016-04-24 Josh Hardman

    What is actually calling showAction()?

  • 2016-04-24 weaverryan

    PHPstorm! With the Darcula theme :). We have some other PHPStorm goodies over here:


  • 2016-04-23 Emilien Ramos

    Please what's your IDE ?

  • 2016-03-23 weaverryan

    Oh no! I have seen in rare cases that it doesn't work for *some* people. I would open a support request with PhpStorm to see if they can help. Make sure you're also using the latest version of PhpStorm - that might not make a difference, but it's worth a try.

  • 2016-03-22 utkarsh srivastava


    I've added php annotations plugin and restarted phpstorm but it still doesnt prompt the autocomplete. Please help me with this.

  • 2016-01-26 weaverryan

    Yea, thanks for pointing this out! There was at least one other user that also commented (on another chapter) - so I've added a note about this: It was an oversight - you *definitely* want this awesome plugin :).


  • 2016-01-24 Levan Lomia

    omg man thank you. I was struggling abaout that too. just read your comment accidentally

  • 2016-01-24 ZB

    Make sure to also install the PHP Annotations plugin to PHP Storm. I was struggling to make that @Route auto-complete work