Symfony2自定义控制台命令在执行时显示为"未定义"

Str*_*sov 14 command symfony

我在src/CollaboratorsBundle/Command中创建了一个新类,将其命名为GenerateFormRemindersCommand.php并将以下代码放入其中:

<?php
namespace Myproject\CollaboratorsBundle\Command;

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;

class GenerateFormRemindersCommand extends ContainerAwareCommand{

    protected function configure() {
        $this->setName("generate:formReminders")
             ->setDescription('Send reminders by email to all collaborators with unanswered forms');
    }

    protected function execute(InputInterface $input, OutputInterface $output) {
        //some code
    }
}
Run Code Online (Sandbox Code Playgroud)

执行时,我收到以下消息:

$ php app/console generate:formReminders
[InvalidArgumentException]
Command "generate:formReminders" is not defined.
Run Code Online (Sandbox Code Playgroud)

我已经在我的AppKernel.php文件中检查了我的捆绑包已在其中注册了.

我尝试过添加parent:configure(); 到configure方法但没有任何结果.

我已经创建了一些其他正常工作的自定义命令.在这种情况下,我不明白我做错了什么.你呢 ?

提前致谢

Via*_*lov 61

我有同样的麻烦,因为我没有"命令"后缀命名文件.您必须将文件命名为"GenerateFormRemindersCommand.php".

  • 你不知道这个答案是多么正确.啧.刚刚结束了半个小时的挫折感. (4认同)

Koe*_*oen 5

我有同样的错误.我遇到的问题是我实现了构造函数来初始化存储库字段而不是initialize()方法.