& Quot; X & quot; аргумент не существует

У меня есть простое консольное приложение Symfony со следующей точкой входа

#!/usr/bin/env php
<?php

include __DIR__ . '/vendor/autoload.php';

use Rkmax\Application;

$app = new Application();
$app->run();

мой класс приложений

class Application extends BaseApplication
{
public function __construct($name = 'myapp', $version = '0.1')
{
parent::__construct($name, $version);

$this->add(new Command\SingleCommand());
}
}

и моя команда

class SingleCommand extends Command
{
const KEYWORDS = 'keywords';

protected function configure()
{
$this
->setName("single")
->setDescription("Sample")
->addArgument(self::KEYWORDS, InputArgument::OPTIONAL, "Keywords for the search")
;
}

public function run(InputInterface $input, OutputInterface $output)
{
$keywords = $input->getArgument(self::KEYWORDS);
// ...
}
}

я не могу понять, где проблема всегда я получаю ошибку

 [InvalidArgumentException]
The "keywords" argument does not exist.

0

Решение

Вы, вероятно, должны переопределить выполнять метод не бежать.

public function execute(InputInterface $input, OutputInterface $output)
{
$keywords = $input->getArgument(self::KEYWORDS);
// ...
}

бежать инициализирует $ вход а также выход, затем проверяет вход и звонки выполнить ($ input, $ output) потом.

https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Console/Command/Command.php#L215-L257

1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector