选择输入 TYPO3 v9 Symfony 命令

我想在 TYPO3 v9 中创建一个调度程序命令,问题是,我不知道也无法找到如何进行选择输入。


这就是我所拥有的:


/**

 * Basic configuration(s) for the command.

 */

protected function configure(): void

{

    $this->setName('WiRo Workflow')

        ->setDescription('Sendet eine E-Mail an den Redakteur, wenn Inhaltselemente länger als 6 Monate nicht bearbeitet wurden')

        ->addArgument('mailFrom', InputArgument::REQUIRED, 'Absender-Adresse')

        ->addArgument('mailFromName', InputArgument::REQUIRED,'Absender-Name')

        ->addArgument('mailTo', InputArgument::OPTIONAL, 'Empfänger-Adresse (nur für Chefredakteure und Administratoren)')

        ->addOption(

            'colors',

            ['blue', 'red'],

            InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,

            'Which colors do you like?',

            ['blue', 'red']

        )

        ->addOption('optionTV', null, InputOption::VALUE_OPTIONAL, 'Benachrichtigung an: Themenverantwortlicher')

        ->addOption('optionAdmin', null, InputOption::VALUE_NONE, 'admin')

        ->addOption('optionAdminAct', null, InputOption::VALUE_NONE, 'Benachrichtigung an: Chefredakteur und Administratoren (Aktualisierung)')

        ->addArgument('mailTimeToCheck', InputArgument::OPTIONAL, 'Anzahl Monate der Seiten, die zu prüfen sind:')

        ->addArgument('urlMandant', InputArgument::OPTIONAL, 'URL des Mandanten')

        ->addArgument('pageContact', InputArgument::OPTIONAL, 'Themenverantwortliche beziehen aus:')

        ->addArgument('rootPageID', InputArgument::OPTIONAL, 'Root-Page')

        ->addArgument('excludePages', InputArgument::OPTIONAL, 'Auszuschließende Seiten (Komma separierte Liste)')

        ->addArgument('mailSignature', InputArgument::OPTIONAL, 'Mail-Signatur');

}


慕的地6264312
浏览 58回答 1
1回答

白衣染霜花

您不能将用户选择问题放在命令选项上...,而是必须使用带有 ChoiceQuestion 对象的帮助器的询问方法来在你的指挥下use Symfony\Component\Console\Question\ChoiceQuestion;// .../** * Basic configuration(s) for the command. */protected function configure(): void{    $this->setName('WiRo Workflow')        ->setDescription('Sendet eine E-Mail an den Redakteur, wenn Inhaltselemente länger als 6 Monate nicht bearbeitet wurden')        ->addArgument('mailFrom', InputArgument::REQUIRED, 'Absender-Adresse')        ->addArgument('mailFromName', InputArgument::REQUIRED,'Absender-Name')        ->addArgument('mailTo', InputArgument::OPTIONAL, 'Empfänger-Adresse (nur für Chefredakteure und Administratoren)')        ->addOption('optionTV', null, InputOption::VALUE_OPTIONAL, 'Benachrichtigung an: Themenverantwortlicher')        ->addOption('optionAdmin', null, InputOption::VALUE_NONE, 'admin')        ->addOption('optionAdminAct', null, InputOption::VALUE_NONE, 'Benachrichtigung an: Chefredakteur und Administratoren (Aktualisierung)')        ->addArgument('mailTimeToCheck', InputArgument::OPTIONAL, 'Anzahl Monate der Seiten, die zu prüfen sind:')        ->addArgument('urlMandant', InputArgument::OPTIONAL, 'URL des Mandanten')        ->addArgument('pageContact', InputArgument::OPTIONAL, 'Themenverantwortliche beziehen aus:')        ->addArgument('rootPageID', InputArgument::OPTIONAL, 'Root-Page')        ->addArgument('excludePages', InputArgument::OPTIONAL, 'Auszuschließende Seiten (Komma separierte Liste)')        ->addArgument('mailSignature', InputArgument::OPTIONAL, 'Mail-Signatur');}protected function execute(InputInterface $input, OutputInterface $output): int{    //...    $helper = $this->getHelper('question');    $question = new ChoiceQuestion(        'Which colors do you like?',        ['blue', 'red'],        0 // default is blue    );    $question->setErrorMessage('Color %s is invalid.');    $color = $helper->ask($input, $output, $question);    $output->writeln('You have just selected: ' . $color);    // doSomething with $color    return 0;}//...
打开App,查看更多内容
随时随地看视频慕课网APP