我正在使用Symfony2 Command
,当我尝试在prod
环境中运行命令时出现错误,但它在dev
中工作得很好:
一切都很好,如果我跑:php app/console mycommand:start
当我运行php app/console mycommand:start --env=prod
我得到这个错误:
[LogicException]
The command defined in "NameSpace\Of\MyClassCommand" cannot have an empty name.
命令定义:
services:
my_service.command:
class: NameSpace\Of\MyClassCommand
arguments:
name: mycommand:start
tags:
- { name: console.command }
指令:
class MyClassCommand extends Command
{
/**
* @param InputInterface $input
* @param OutputInterface $output
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
// logic
}
...
}
正如你可能注意到的,我没有重载__construct
或configure
方法。我试过了,但它没有改变任何东西。如果我清理该高速缓存,情况也是一样。
有没有人知道prod
和dev
环境之间的区别是什么,导致了这个问题?
谢谢你
3条答案
按热度按时间9w11ddsr1#
清除缓存对我来说不起作用。我需要将基类声明为
abstract class
以提示Symfony不要将其注册为命令。cnwbcb6i2#
我终于找到了解决办法,鲁斯兰你是对的:清除该高速缓存。但我不得不手动核攻击该高速缓存文件夹,
cache:clear
命令是不够的。w80xi6nr3#
下面是Symfony 6中相同问题的答案。
如果命令被定义为...
symfony console list
产生...问题是代码缺少一个引用...