Mrcdh技术博客 Mrcdh技术博客
首页
  • Html5
  • Javascript
  • Nodejs
  • electron
  • Android
  • 微信公众号
  • 框架
  • 其他
  • Mysql
  • PHP
  • Python
  • java
  • Gulp
  • 其它
  • 网站
  • 资源
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

Mrcdh

全栈开发小学生
首页
  • Html5
  • Javascript
  • Nodejs
  • electron
  • Android
  • 微信公众号
  • 框架
  • 其他
  • Mysql
  • PHP
  • Python
  • java
  • Gulp
  • 其它
  • 网站
  • 资源
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • ThinkPHP

    • thinkphp消息队列think-queue的基本使用
    • tp5自定义命令行
    • ThinkPHP常见问题
  • FastAdmin

  • laravel

  • laravel-jetstream.vue

  • laravel常用扩展包

  • 《PHP框架》
  • ThinkPHP
mrcdh
2024-05-10

tp5自定义命令行

创建自定义命令文件Custom.php

<?php
namespace app\common\command;

use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\console\input\Option;

class Custom extends Command
{
    
    protected function configure()
    {
        $this->setName('test') // 自定义名称: php think test
            ->setDescription('这是命令的描述') // 定名命令的描述
            ->addArgument('name') // 增加一个名字参数: php think test 张三
            ->addArgument('age', Option::VALUE_OPTIONAL, '年龄') // 增加一个名字参数: php think test 张三 16
            ->addOption('student') // 定义附加选项: php think test 张三 16 --student
            ->addOption('sex', 's', Option::VALUE_OPTIONAL, '1=男,2=女', '1') // 定义附加选项: php think test 张三 16 --student --sex=2
        ;
    }

    protected function execute(Input $input, Output $output)
    {
        //获取输入的参数
        $name = $input->getArgument('name');

        // 是否包含student选项
        $input->hasOption('student');
        // 获取选项的值
        $sex = $input->getOption('sex');

        $output->writeln('Hello World');//在命令行界面输出内容
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

配置命令application/command.php

return [
    'app\common\command\Custom'
];
1
2
3
#thinkphp
上次更新: 2024/05/10, 14:29:22
thinkphp消息队列think-queue的基本使用
ThinkPHP常见问题

← thinkphp消息队列think-queue的基本使用 ThinkPHP常见问题→

最近更新
01
uniapp常见问题
03-19
02
Vue3项目搭建
12-25
03
使用pnpm的monorepo组织项目
11-01
更多文章>
Theme by Vdoing | Copyright © 2020-2025 Mrcdh | 苏ICP备2020058908号-1
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
×