随笔 - 612, 文章 - 0, 评论 - 31, 阅读 - 74万

导航

< 2025年3月 >
23 24 25 26 27 28 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 1 2 3 4 5

TP6:第一个Command

Posted on   eastson  阅读(736)  评论(0编辑  收藏  举报

ThinkPHP提供自定义命令功能,参考手册

如何自定义TP6的命令,参考thinkphp6 command(自定义指令)

1. 建立app/test/command/Hello.php。

<?php
declare (strict_types = 1);

namespace app\test\command;

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

class Hello extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('hello')
            ->setDescription('the hello command');
    }

    protected function execute(Input $input, Output $output)
    {
        // 指令输出
        $output->writeln('Hello ' . date('Y-m-d H:i:s'));
    }
}

2. 配置config\console.php。

<?php

return [
    'commands' => [
        'app\test\command\Hello',
    ],
];

3. 测试命令执行结果。

相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 字符编码:从基础到乱码解决
历史上的今天:
2014-05-10 How to authenticate a user by uid and password?
2014-05-10 LDAP 中 CN,OU,DC 的含意
2014-05-10 Apache Directory Studio
2014-05-10 LDAP编辑器 LDAPAdmin
2013-05-10 Windows XP下获取OpenERP源码
2013-05-10 关于OpenERP客户端字体问题的一点心得
点击右上角即可分享
微信分享提示