创建命令行

    你应该看到一个命令列表,可以给你调试信息,帮助生成代码,生成数据库迁移等等。 当你安装更多的以来扩展时,你会看到更多的命令。

    1. $ php bin/console route

    如果想要获取更多的命令参数,可以通过 —help-h 选项进行获取。

    1. $ php bin/console route -h
    1. <?php
    2. namespace Console;
    3. use Symfony\Component\Console\Input\InputArgument;
    4. use Symfony\Component\Console\Input\InputInterface;
    5. use Symfony\Component\Console\Output\OutputInterface;
    6. class HelloConsole extends Command
    7. {
    8. public function configure()
    9. $this->addArgument('name', InputArgument::OPTIONAL, '', 'jan');
    10. }
    11. public function execute(InputInterface $input, OutputInterface $output)
    12. {
    13. $output->writeln('hello '.$input->getArgument('name'));
    14. }

    由于我们功能实现引用了 Symfony/console