为了账号安全,请及时绑定邮箱和手机立即绑定

选择输入 TYPO3 v9 Symfony 命令

选择输入 TYPO3 v9 Symfony 命令

PHP
慕的地6264312 2023-10-21 09:58:46
我想在 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');}
查看完整描述

1 回答

?
白衣染霜花

TA贡献1796条经验 获得超10个赞

您不能将用户选择问题放在命令选项上...,而是必须使用带有 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;

}

//...


查看完整回答
反对 回复 2023-10-21
  • 1 回答
  • 0 关注
  • 55 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信