skip to Main Content

I have a project legacy that I have been updating since symfony 2. Now I am at 6.4 however my routes stoped working.

In my routing.yml i am trying to fix the routes in the Admin folder.
Following the documentation https://symfony.com/doc/6.4/routing/custom_route_loader.html
but is not working.

I have tried:

app_admin:
  resource: ../../src/AppBundle/Controller/Admin/
  type: attribute

And the error is:

In FileLoader.php line 182:
                                                                                                                                                                                                                       
  Warning: Array to string conversion in app/config/../../src/AppBundle/Controller/Admin/ (which is being imported from app/config/routing.yml"). Make sure there is a loader supporting the "attribute" type.                                                                                                                         
                                                                                                                                                                                                                       

In AttributeClassLoader.php line 219:
                                       
  Warning: Array to string conversion  
                                       

I also have tried:

app_admin:
  # loads routes from the PHP attributes of the controllers found in the given PSR-4 namespace root
  resource:
    path: '../../src/AppBundle/Controller/Admin/'
    namespace: AppControllerAdmin
  type: attribute

However the $ php bin/console debug:router
does not load any routes.

enter image description here

If I change the routing.yml to add each class it works, but I don’t think it is the best way to do it. Adding each class is going to be a pain.

enter image description here

AdminController

<?php

namespace AppBundleControllerAdmin;


use AppBundleServiceSmsMailer;
use AppBundleEntityCletClient;
use SymfonyBundleFrameworkBundleControllerAbstractController;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentMailerMailerInterface;
use SymfonyComponentNotifierTexterInterface;
use SymfonyComponentRoutingAnnotationRoute;

class AdminController extends AbstractController
{

    #[Route(path: '/admin/', name: 'admin')]
    public function showAction(){

        return $this->render("@App/admin/show.html.twig", array(
            '' => '',
        ));
    }

    /**
     * @Route("/admin/sales-chart/", options={"expose"=true},name="sales_chart_data")
     */
    public function getSalesChartDataAction(){


        $json = '{}';
        $result = json_decode ($json);
        return new Response(json_encode($result));

    }

    /**
     * @Route("/file_manager/", name="file_manager")
     */
    public function fileManager(){

        return $this->render("@App/admin/blank.html.twig", array(
        ));
    }

    /**
     * @Route("/2fa_email/", name="two_factor_email")
     */
    public function twoFactorEmail(MailerInterface $mailer, TexterInterface $texter){

        return $this->redirectToRoute("2fa_login");
    }
}

Anyone have a clue what I am missing?

2

Answers


  1. Chosen as BEST ANSWER

    I've identified the issue. Many of my routes include parameters that are no longer supported, such as 'options' and 'requirements.' Once these were removed, the routes were successfully restored.

    For example:

    /**
     * @Route("", name="", options={"expose"=true}, requirements={"_format" = "xml"})
    */
    

    By updating and eliminating the outdated parameters, we were able to resolve the problem.

    Ps: I still need to change all annotation to attribute


  2. I encountered the same issue. For me the solution was to replace the Symfony 5.4 Kernel.php file in src folder with one of a fresh Symfony 6.4 install :

    Just run the following : composer create-project symfony/skeleton:"6.4.*" symfony6

    Then, in your newly created symfony6 project, you should find in the src folder a Kernel.php file looking like this :

    <?php
    
    namespace App;
    
    use SymfonyBundleFrameworkBundleKernelMicroKernelTrait;
    use SymfonyComponentHttpKernelKernel as BaseKernel;
    
    class Kernel extends BaseKernel
    {
        use MicroKernelTrait;
    }
    
    

    Also, I am not 100% sure about that as I could not find any confirmation in the Symfony documentation, but I think the old Routes annotation is no longer supported and native PHP 8 attributes notation should be used instead, like you started to do so with the admin route.

    Hope it helps.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search