从命令调用动作 [英] Calling action from command

查看:92
本文介绍了从命令调用动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过自定义命令执行操作。前向方法Controller.php类提供了此功能,但我不知道可以从命令文件的execute()方法访问它

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

推荐答案

为控制器提供服务将由于请求堆栈而导致性能开销,因为它随后应返回 HttpResponse Request 范围在命令中不是很有用。

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.

我建议您从以下位置重构操作将Controller设置为单独的服务类定义,并通过将其设为 ContainerAwareCommand 从控制器和命令中的容器中获取该类。

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

这篇关于从命令调用动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆