我有一个带有以下入口点的简单 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.
最佳答案
您可能应该覆盖execute 方法而不是run。
public function execute(InputInterface $input, OutputInterface $output)
{
$keywords = $input->getArgument(self::KEYWORDS);
// ...
}
run 初始化$input 和output,然后验证input 并调用execute($输入,$output) 稍后。
关于php - "X"参数不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27931283/