创建命令行
你应该看到一个命令列表,可以给你调试信息,帮助生成代码,生成数据库迁移等等。 当你安装更多的以来扩展时,你会看到更多的命令。
$ php bin/console route
如果想要获取更多的命令参数,可以通过 —help
,-h
选项进行获取。
$ php bin/console route -h
<?php
namespace Console;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class HelloConsole extends Command
{
public function configure()
$this->addArgument('name', InputArgument::OPTIONAL, '', 'jan');
}
public function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('hello '.$input->getArgument('name'));
}
由于我们功能实现引用了 Symfony/console
。