Home > PHP Framework > ThinkPHP > body text

How to use the command line (cli) think call in ThinkPHP

coldplay.xixi
Release: 2020-07-03 14:25:28
forward
4636 people have browsed it

How to use the command line (cli) think call in ThinkPHP

In some scenarios, we need to call the code in the command line

  1. First, in application\command Create a new hello.php in the directory (create it if it does not exist):
    <?php
    namespace app\command;
    use think\console\Command;
    use think\console\Input;
    use think\console\input\Argument;
    use think\console\input\Option;
    use think\console\Output;
    use think\Request;
    class hello extends Command {
     /**
      * 重写configure
      * {@inheritdoc}
      */
     protected function configure()
     {
         $this
             // 命令的名字("think" 后面的部分)
             ->setName(&#39;hello&#39;)
             // 配置一个参数 使用$input->getArgument(&#39;username&#39;)获取
             // ->addArgument(&#39;username&#39;)
             // 运行 "php think list" 时的简短描述
             ->setDescription(&#39;定时任务微服务.&#39;)
             // 运行命令时使用 "--help" 选项时的完整命令描述
             ->setHelp("定时任务微服务 无参数");
     }
     /**
      *  * 重写execute
      *  * {@inheritdoc}
      *  
      * @param Input $input
      * @param Output $output
      */
     protected function execute(Input $input, Output $output)
     {
         echo &#39;hello world&#39;;
     }}
    Copy after login
  2. Modify application/command.php (create it if it does not exist)
    <?php
    return [
     "app\command\hello",];
    Copy after login
  3. cd to the project root directory and enter
    php think hello
    Copy after login
    # on the command line.
  4. ##OK, successfully called
    hello world
    Copy after login
Related learning recommendations:

PHP programming from entry to proficiency

The above is the detailed content of How to use the command line (cli) think call in ThinkPHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!