2

I am following the openclassrooms tutorial on symfony. I am now currently at the chapter "Les controleurs avec Symfony".

I try to open http://localhost/Symfony/web/app_dev.php and get this error

NotFoundHttpException

I suspect the error to come from AdvertController.php. But I compared it with the given code at the tutorial. And it is exactly the same. I tried then to delete the cache but it does not function. I will open another question for that.

Here is the AdvertController.php code:

<?php
//src/Neo/PlatformBundle/Controller/AdvertController.php
namespace Neo\PlatformBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
//use Symfony\Component\Routing\Generator\UrlGeneratorInterface;


class AdvertController extends Controller
{
    public function indexAction()
    {
      $url= $this->get('router')->generate(
    'neo_platform_view', //first argument : path name
    array('id' => 5)
  );
    return new Response("The url of the announcement is:".$url);
}

public function viewAction($id)
{
  return new Response("Desplay of the announcment with id:".$id);
}

public function viewSlugAction($slug, $year, $_format)

  {

      return new Response(

          "We could desplay the announcment conrresponding the the slug          
'".$slug."', created in ".$year." and with the format ".$_format."."

          );

      }


}



?>

If you would like me to post other parts of code, please let me know. I have no idea, where to look at.

Thank you very much!

2 Answers 2

2

You can try to dump your routes with the command php bin/console debug:router or app/console for symfony <3.0 to see if there is a route your your desired path. If you have the prefix /platform, your paths inside your controller are now /platform/path instead of /path.

You need a default route for your root path.

Sign up to request clarification or add additional context in comments.

3 Comments

Hello Lerminou! I tried the command you mentioned but I get this message: Could not open input file: bin/console Also in the app/config/routing.yml I have a default route defined as prefix: /platform. Actually, I could fix my problem here stackoverflow.com/questions/46240068/… but I am curious about the debug:router. Any idea how to make it work on my console? Thanks
You need to be at the root path of your application. If you have symfony v2.X, you must use app/console instead of bin/console (launch it just as any other console command)
Thank you Lerminou. Actually I do not know how to place my self at the root path. When I want to open my Symfony folders, I need always to write gksudo nautilus /opt/lammp/htdocs on the console to make them visible. After doing this, the terminal window does not accept other commands. I need to open another terminal window to make other actions. I will ask this question separately in another post.
0

The message error is very explicit, there are not routes for "/". Try to verify your routing.yml

1 Comment

Hello! Thank you for the comment. I actually checked the app/config/routing.yml: Inside I had written: prefix: /platform For this reason thought that Rersources/config/routing.yml only neads the path: /{page} and not path: /{page}. I am doing exactly like in the tutorial. How could I fix this? Thanks a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.