I am novice at Symfony. Current version : 2.8.16 My problem : I don't manage redirection.
app/config/routing.yml :
gb_platform:
resource: "@GBPlatformBundle/Resources/config/routing.yml"
prefix: /platform
src/GB/PlatformBundle/Ressources/config/routing.yml :
gb_platform_home:
path : /{page}
defaults:
_controller : GBPlatformBundle:Advert:index
page: 1
requirements:
page: \d*
gb_platform_view:
path : /advert/{id}
defaults: { _controller : GBPlatformBundle:Advert:view }
requirements:
id: \d+
src/GB/PlatformBundle/Controller/AdvertController.php :
namespace GB\PlatformBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
class AdvertController extends Controller
{
public function indexAction()
{
$url = $this->get('router')->generate(
'gb_platform_view',
array( 'id' => 5)
);
return new Response("L'url de l'annonce d'id 5 est : ". $url);
}
public function viewAction($id)
{
return $this->redirectToRoute('gb_platform_home');
//return new Response("lol");
}
}
The error is the following :
Unable to generate a URL for the named route "gb_platform_home" as such route does not exist.
I can access manually to both route ("app_dev.php/platform/" can be reached). But the URL generation is only working for gb_platform_view.
I supposed the source of the problem could be in app/config/routing.yml file specifying no itteration ... but if I do so it doesn't solve anything and seems to create more problems.
I find the debugging route command line :
php app/console debug:router
Here is the result.
gb_platform_home is clearing identify as a know route so I don't understand. Also, you may notice there's a shifted unique print for this route in the shell. Why ? Key for solving ?
Could a 4 spaces encoding be the problem ?
Thanks for your help.
page
value with your route usage. Something likereturn $this->redirectToRoute('gb_platform_home', array('page'=>0));
– Piyush Singh/platform/index/{page}
instead. Sometimes the routing sees it as ambiguous when the variable is not explicitly defined in the route. – Piyush Singhgb_platform_home
line slightly to the left, compared to the rest? looks unusual. It came like this directly, or was this edited in any way? – yivi