phpsymfonysymfony5sylius

Controller not being registered as a service correctly?


I am trying to create a basic EntryController controller with admin route in my Sylius/Symfony 5 setup.

My src/Controller/EntryController.php looks as follows:

<?php

namespace App\Controller;


use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;


class EntryController extends AbstractController
{

    /**
     * @param Request $request
     * @return Response
     */
    public function indexAction(Request $request): Response
    {
       dd('THIS CONTROLLER IS WORKING!');
    }

}

The route for my controller src/Resources/config/routing/admin/order_form.yml looks like the below:

sylius_complete_order_form:
  path: /order/form
  methods: [GET]
  controller: App\Controller\EntryController::index

And my controller is defined as a service inside config/services.yaml:

# Controllers are imported separately to make sure services can be injected
# as action arguments even if you don't extend any base controller class
App\Controller\:
    resource: '../src/Controller'
    public: true
    autowire: true
    tags: ['controller.service_arguments']

Currently when I try navigate to the path of the sylius_complete_order_form route defined above, I am getting the below error:

"App\Controller\EntryController" has no container set, did you forget to define it as a service subscriber?

I don't understand why this is happening?

Any help or guidance would be greatly appreciated. Let me know should I need to include additional info.


Solution

  • I have managed to get my controller working by doing a few steps:

    1. Remove the service definition of the EntryController from services.yaml
    2. Extend AbstractController

    class EntryController extends AbstractController

    1. Enable autowire & make the controller public inside my services.yaml config/services.yaml

      App\Controller: resource: '../src/Controller' public: true autowire: true tags: ['controller.service_arguments']