Home > Net >  Symfony 6.1 Ignoring Controller and the routes inside it
Symfony 6.1 Ignoring Controller and the routes inside it

Time:10-28

I'm converting a Symfony 3.4 site to 6.1. I created a brand new 6.1 site and am copying elements over 1-by-1. I'm using Attributes to define routes inside Controllers (no changes to routing.yaml).

I was working on some fixes in the CustomerController, when suddenly I started getting route does not exist errors for the routes inside that Controller. All other routes are working perfectly. Routes within this Controller were previously working perfectly.

I ran bin/console debug:router and sure enough, the routes inside the CustomerController are missing. However, the CustomerController.php file is still there, it has the correct permissions, as far as I can tell there are no syntax errors, but even if there were, I should be able to see the syntax errors instead of route does not exist errors, no?

As far as I can tell, Symfony is simply ignoring the existence of the CustomerController.php file. How can that be? How can I get it to include it again?

I have run bin/console cache:clear but it had no effect on this.

EDIT: I deliberately introduced a syntax error into the CustomerController.php file and refreshed the page in the browser, sure enough Symfony showed me the syntax error. I fixed the syntax error and the error went back to route does not exist - even though the route does exist in the CustomerController.php file and was previously working.

There is no further information in the log file other than the missing route exception.

EDIT2: Here's the first route and function in the Controller:

    #[Route('/sales/customer', name: 'customer')]
    public function index(): Response
    {
        return $this->render('customer/list.html.twig', [
            'controller_name' => 'CustomerController',
            'list' => 'customer'
        ]);
    }

CodePudding user response:

Try to fetch the links as a loop inside you template file (Twig). Something like this:

{% for post in posts %}  
        <a href={{ path('post_show', {'id' : post.id}) }}> 
                <p>Anytext here</p>
        </a> 
{% endfor %}

Any list will appear?

CodePudding user response:

I eventually managed to reverse out the changes I had been making, and saw that I had deleted use Symfony\Component\Routing\Annotation\Route; - putting this back solved the problem! Shame that Symfony can't alert you to this kind of problem...

  • Related