Daniel
Daniel

Reputation: 15453

Why does Symfony not find this route?

I am developing an app with Symfony 3.2.0 on a Mac OSX El Capitan and I am able to view http://127.0.0.1:8000/category/create but when I go to /category/edit/1 I get this 404 error:

No route found for "GET /category/edit/1"

Here is my CategoryController.php:

<?php

namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

class CategoryController extends Controller
{
    /**
     * @Route("/categories", name="category_list")
     */
    public function indexAction(Request $request)
    {
        // replace this example code with whatever you need
        return $this->render('category/index.html.twig', [
            'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
        ]);
    }

    /**
     * @Route("/category/create", name="category_create")
     */
    public function createAction(Request $request)
    {
        // replace this example code with whatever you need
        return $this->render('category/create.html.twig', [
            'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
        ]);
    }

    /**
     * @Route("/category/edit/{id}", name="category_edit")
     */
    public function editAction(Request $request)
    {
        // replace this example code with whatever you need
        return $this->render('category/edit.html.twig', [
            'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
        ]);
    }

    /**
     * @Route("/category/delete/{id}", name="category_delete")
     */
    public function deleteAction(Request $request)
    {

    }
}

I have created the edit.html.twig file in category folder.

ldco2016@DCortes-MacBook-Pro-3 ~/Projects/eventcalendar $ php bin/console debug:router --env=prod                                                                    [ruby-2.2.1]
 ----------------- -------- -------- ------ -----------------------
  Name              Method   Scheme   Host   Path
 ----------------- -------- -------- ------ -----------------------
  category_list     ANY      ANY      ANY    /categories
  category_create   ANY      ANY      ANY    /category/create
  category_delete   ANY      ANY      ANY    /category/delete/{id}
  homepage          ANY      ANY      ANY    /
  event_list        ANY      ANY      ANY    /events
  event_create      ANY      ANY      ANY    /event/create
  category_edit     ANY      ANY      ANY    /event/edit/{id}
  event_delete      ANY      ANY      ANY    /event/delete/{id}
 ----------------- -------- -------- ------ -----------------------

Upvotes: 0

Views: 246

Answers (1)

Federkun
Federkun

Reputation: 36964

A good way to debug this is to run this command:

php bin/console debug:router --env=prod

This will show you all the routes with their paths, and (as in this case) see if they are been overridden by some other routes with the same name.

Upvotes: 2

Related Questions