php - Route "does not exist" in Symfony even though it's declared in main routing file -
here contents of relevant files :
contents of app/config/routing.yml :
horse_route: path: /horse defaults: { _controller: appbundle:horse:show } app: resource: "@appbundle/controller/" type: annotation contents of src/appbundle/controller/walruscontroller.php :
<?php namespace appbundle\controller; use sensio\bundle\frameworkextrabundle\configuration\route; use symfony\component\httpfoundation\response; use symfony\bundle\frameworkbundle\controller\controller; class walruscontroller extends controller { /** * @route("/walrus/red") */ public function walrusredirect() { return $this->redirecttoroute('/horse', array(), 301); } } contents of src/appbundle/controller/horsecontroller.php :
<?php namespace appbundle\controller; use sensio\bundle\frameworkextrabundle\configuration\route; use symfony\component\httpfoundation\response; use symfony\bundle\frameworkbundle\controller\controller; class horsecontroller extends controller { public function showaction() { return new response('this horse.'); } } when type localhost:8000/walrus/red in browser, error message
unable generate url named route "/horse" such route not exist. it seems either did not declare route correctly in main routing file, or declared in wrong place. appreciated.
your route called horse_route need use
return $this->redirecttoroute('horse_route', array(), 301);
Comments
Post a Comment