D
D
Div-Man2018-12-23 21:17:24
symfony
Div-Man, 2018-12-23 21:17:24

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.

and if you change to the root , then it's also an error
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

1 answer(s)
V
Vadim, 2018-12-23
@kylt_lichnosti

https://symfony.com/doc/current/routing.html#gener...
The generateUrl parameter should be the name of the route.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question