1
votes

I'm newbie in Symfony and I'm following a tutorial. The first excercise is very simple, but I don't know why is not working.

In my source folder I first tried with these lines:

<?php

namespace AppBundle\Controller;


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

class GenusController
{
    /**
     * @Route("/genus")
     */

    public function showAction()
    {
        return new Response('Test ');

    }

}

I tried in in my browser:

http://localhost:8888/my_project/web/genus

And it works. But then if I add new lines:

class GenusController
{
    /**
     * @Route("/genus/{genusName}")
     */

    public function showAction($genusName)
    {
        return new Response('The genus: '.$genusName);

    }

}

and tested it:

http://localhost:8888/my_project/web/genus/test

My browser displays:

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.

What is missing? Any suggestions?

Thank you in advance

1
How to you start your application, php bin/console server:start? If you do, the proper url should be: http://localhost:8888/genus/something - Boris Guéry
Have you tried to access from your dev environment ? localhost:8888/my_project/web/app_dev.php/genus/test otherwise, try to clear your cache. - fliim
I didn't start my application through php bin/console server:start. I'm using MAMP and I thought that I didn't have to do something else - marhg
@fliim I just tried and I got the error No route found for "GET /genus/test", By the way, in the tutorial they recommended to mark the "src" folder as Sources Root, does that impact somehow? - marhg

1 Answers

0
votes

In prod environment: the configuration information is cached and not automatically refreshed. It means:

  • @nnotation in php files are cached
  • .yml file are cached
  • .xml file are cached
  • *.twig file are cached

The error you are having is the new route you've created is not cached and not accessible to prod environment.

It means you either have to call app/console cache:clear --env=prod everytime or you have to use the dev environnement which is far better when developping. It provides better error message for 404 and 500 errors too.

It means you have to use the app_dev.php instead of app.php. You can try

http://localhost:8888/app_dev.php/my_project/web/genus/test