Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling action from command

I want to perform an action from a custom command. The forward method Controller.php class provides this function, but I do not know access it from the execute () method of the command file

like image 295
Yvon PLANCADE Avatar asked Jul 20 '15 08:07

Yvon PLANCADE


2 Answers

Making the controller a service will result in performance overhead because of the request stack, as it then should return a HttpResponse. The Request scope will not be very usefull in the command.

I'd advise you to refactor the action from the Controller to a separate service class definition, and get that class from the container in both the controller and the command by making it a ContainerAwareCommand.

http://symfony.com/doc/current/cookbook/console/console_command.html#getting-services-from-the-service-container

like image 151
Rvanlaak Avatar answered Sep 29 '22 17:09

Rvanlaak


Use controller as service How to Define Controllers as Service

like image 33
sav Avatar answered Sep 29 '22 17:09

sav