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 have tried manually clearing the cache by deleting var/cache
folder.
I have tried running php bin/console cache:clear
When I run php bin/console debug:container EntryController
the output is the below:
Service ID App\Controller\EntryController
Class App\Controller\EntryController
Tags controller.service_arguments
Calls setContainer
Public yes
Synthetic no
Lazy no
Shared yes
Abstract no
Autowired yes
Autoconfigured no
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.
I have managed to get my controller working by doing a few steps:
class EntryController extends AbstractController
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']