Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 custom console command appears as "not defined" upon execution

I created a new Class in src/CollaboratorsBundle/Command, named it GenerateFormRemindersCommand.php and put the following code in it:

<?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
    }
}

Upon execution, i get the following message :

$ php app/console generate:formReminders
[InvalidArgumentException]
Command "generate:formReminders" is not defined.

I've checked in my AppKernel.php file that my bundle was registered in it and it was.

I've tried adding parent:configure(); to the configure method but without any results.

I've created a few other custom commands that work correctly. I don't get what I am doing wrong in this case. Do you ?

Thanks in advance

like image 764
Streltsov Avatar asked Apr 17 '13 12:04

Streltsov


1 Answers

I had the same trouble because I named file without "Command" suffix. You have to name your file as 'GenerateFormRemindersCommand.php'.

like image 85
Viacheslav Dobromyslov Avatar answered Nov 09 '22 23:11

Viacheslav Dobromyslov