小编jac*_*ndl的帖子

来自控制器的Console/Symfony Call命令

当我尝试从Controller调用命令时,我在控制台上遇到了一些问题.我在Symfony CookBook中找到了一种方法:http: //symfony.com/doc/current/cookbook/console/command_in_controller.html

它似乎不起作用......也许我忘了一些东西!

命令:

namespace AppBundle\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class GreetCommand extends Command
{
    protected function configure()
    {
        $this
            ->setName('demo:greet')
            ->setDescription('Greet someone')
            ->addArgument(
                'name',
                InputArgument::OPTIONAL,
                'Who do you want to greet?'
            )
            ->addOption(
                'yell',
                null,
                InputOption::VALUE_NONE,
                'If set, the task will yell in uppercase letters'
            )
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $name = $input->getArgument('name');
        if ($name) {
            $text = 'Hello '.$name;
        } …
Run Code Online (Sandbox Code Playgroud)

php console symfony

4
推荐指数
1
解决办法
4722
查看次数

标签 统计

console ×1

php ×1

symfony ×1