Php “X”参数不存在
我有一个简单的symfony控制台应用程序,具有以下入口点Php “X”参数不存在,php,symfony,console-application,Php,Symfony,Console Application,我有一个简单的symfony控制台应用程序,具有以下入口点 #!/usr/bin/env php <?php include __DIR__ . '/vendor/autoload.php'; use Rkmax\Application; $app = new Application(); $app->run(); 还有我的命令 class SingleCommand extends Command { const KEYWORDS = 'keywords';
#!/usr/bin/env php
<?php
include __DIR__ . '/vendor/autoload.php';
use Rkmax\Application;
$app = new Application();
$app->run();
还有我的命令
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方法not run run初始化$input和output,然后验证输入并稍后调用execute$input、$output
您可能应该重写execute方法not run run初始化$input和output,然后验证输入并稍后调用execute$input、$output
getArgument看起来像什么?我不明白你的问题$keywords=$input->getArgumentself::keywords;getArgument方法看起来像什么?当你用addArgument定义一个参数时。。。在configure方法中。您可以使用$input->getArgument使用相同的名称进行检索,以避免输入错误。我使用const作为参数/选项名称。好的,您在哪里调用addArgument???getArgument看起来像什么?我不明白你的问题$keywords=$input->getArgumentself::keywords;getArgument方法看起来像什么?当你用addArgument定义一个参数时。。。在configure方法中。您可以使用$input->getArgument使用相同的名称进行检索,以避免输入错误。我使用const作为参数/选项名称。好的,您在哪里调用addArgument???是的,托马斯,我是来检查的是的,托马斯,我是来检查的
[InvalidArgumentException]
The "keywords" argument does not exist.
public function execute(InputInterface $input, OutputInterface $output)
{
$keywords = $input->getArgument(self::KEYWORDS);
// ...
}