2017-01-05 5 views
2

Ich möchte meinem Konsolenbefehl doctrine:fixtures:load eine neue Option hinzufügen.Neue Option zum LoadDataFixture-Befehl hinzufügen

class LoadDataFixturesCommand extends LoadDataFixturesDoctrineCommand 
{ 
    /** 
    * {@inheritDoc} 
    */ 
    protected function configure() 
    { 
     parent::configure(); 

     $this->addOption('custom', null, InputOption::VALUE_OPTIONAL, 'Your Custom Option'); 
    } 
} 

Als ich betreibe meine Befehl wie folgt aus:

Lehre: Leuchten: load --custom

ich diese Fehlermeldung bekommen:

[Symfony \ Component \ Console \ Exception \ RuntimeException]
Die Option "--custom" existiert nicht.

Wie kann ich diese Option zu meinem Konsolenbefehl hinzufügen?

+0

Haben Sie 'symfony \ Component \ Console \ Input \ InputOption;' und 'symfony \ Component \ Console \ Input \ InputInterface;' in Ihrer Klasse 'LoadDataFixturesCommand' hinzugefügt? – Hokusai

+0

Ja, alles hinzugefügt. So ist es nicht. Erklärungen sind in Ordnung, und die Fixtures-Klasse wurde bereits geladen. Die Nachricht kommt gleich danach. – Roland

+0

Ich denke, dass diese Frage nützlich sein könnte: http://stackoverflow.com/questions/26596218/how-to-get-command-argument-outside-command-class – Hokusai

Antwort

0

können Sie die Funktion umbenennen:

protected function configure() 
    { 
     parent::configure(); 

     $this->setName('app:fixtures:load') 
      ->addOption('custom-option', null, InputOption::VALUE_OPTIONAL, 'Your Custom Option'); 
    } 

auf diese Weise den Befehl

php app/console app:fixtures:load 

werden Sie persönliche Funktion ausführen aufrufen.

Verwandte Themen