Answer the question
In order to leave comments, you need to log in
Why is the generateUrl redirect not working?
Outputs an error
Unable to generate a URL for the named route "/blog/{page}" as such route does not exist.
return $this->redirect($this->generateUrl('/'));
app:
resource: '@AppBundle/Controller/'
type: annotation
blog_list:
path: /blog/{page}
defaults: { _controller: AppBundle:Blog:list, page: 1 }
requirements:
page: '\d+'
blog_show:
path: /blog/{slug}
defaults: { _controller: AppBundle:Blog:show }
<?php
// src/AppBundle/Controller/BlogController.php
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\HttpFoundation\Response;
class BlogController extends AbstractController
{
public function listAction($page = 1)
{
echo 333;
echo '<br>';
echo '<br>';
die($page);
}
public function showAction ( $slug )
{
return $this->redirect($this->generateUrl('/blog/{page}'));
die($slug);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question