Answer the question
In order to leave comments, you need to log in
How to scatter routing in Symfony 3?
I'm learning Symfony, I just can't handle routing through annotations and yml configs.
It is necessary that all routing in my asoft/OrganizerBundle project be annotated in controllers.
Registered:
E:\Program Files\Apache24\htdocs\symfony.local\organizer\app\config\routing.yml
organizer:
resource: "@OrganizerBundle/Resources/config/routing.yml"
app:
resource: '@AppBundle/Controller/'
type: annotation
organizer:
resource: "@OrganizerBundle/Controller/"
type: annotation
<?php
declare(strict_types = 1);
namespace asoft\OrganizerBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class DefaultController extends Controller
{
/**
* @Route("/")
*/
public function showMainAction(): Response
{
return $this->showDayAction((new \DateTime())->format('Y-m-d'));
}
/**
* @Route("/{day}")
*/
public function showDayAction(string $day): Response
{
echo $day;
return $this->render('OrganizerBundle:Default:index.html.twig');
}
}
request.CRITICAL: Uncaught PHP Exception InvalidArgumentException: "The controller for URI "/" is not callable. Expected method "indexAction" on class "asoft\OrganizerBundle\Controller\DefaultController". Available methods: "showMainAction", "showDayAction", "setContainer"." at E:\Program Files\Apache24\htdocs\symfony.local\organizer\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Controller\ControllerResolver.php line 98 {"exception":"[object] (InvalidArgumentException(code: 0): The controller for URI \"/\" is not callable. Expected method \"indexAction\" on class \"asoft\\OrganizerBundle\\Controller\\DefaultController\". Available methods: \"showMainAction\", \"showDayAction\", \"setContainer\". at E:\\Program Files\\Apache24\\htdocs\\symfony.local\\organizer\\vendor\\symfony\\symfony\\src\\Symfony\\Component\\HttpKernel\\Controller\\ControllerResolver.php:98)"} []
request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "GET /2007-05-02"" at E:\Program Files\Apache24\htdocs\symfony.local\organizer\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\EventListener\RouterListener.php line 125 {"exception":"[object] (Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException(code: 0): No route found for \"GET /2007-05-02\" at E:\\Program Files\\Apache24\\htdocs\\symfony.local\\organizer\\vendor\\symfony\\symfony\\src\\Symfony\\Component\\HttpKernel\\EventListener\\RouterListener.php:125, Symfony\\Component\\Routing\\Exception\\ResourceNotFoundException(code: 0): at E:\\Program Files\\Apache24\\htdocs\\symfony.local\\organizer\\var\\cache\\prod\\appProdProjectContainerUrlMatcher.php:56)"} []
Answer the question
In order to leave comments, you need to log in
It all worked when I wrote in the global and bundled routing.yml, respectively:
organizer:
resource: '@OrganizerBundle/Resources/config/routing.yml'
organizer:
resource: "@OrganizerBundle/Controller/DefaultController.php"
type: annotation
In the showMainAction annotation, assign the name parameter. You should get something like:
/**
* @Route("/", name="show_main")
*/
/**
* @Route("/day/{day}", name="show_day")
*/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question