网站制作学习网PHP→正文:thinkphp6 command 命令行
字体:

thinkphp6 command 命令行

PHP 2023/4/23 17:22:43  点击:不统计

http://%77%77%77%2E%66网站制作%6F学习网%72%61%73%70%2E%63%6E

1. thinkphp6 创建命令行command
命令如下:
php think make:command Bdsitemap bdsitemap
命令行含义解释
php # 调用本地php bin
think #调用thinkphp框架命令
make:command # 创建命令行名称,还有比如:make:controller 创建控制器等等
Bdsitemap # 命令行执行类文件和对应类名称
bdsitemap # 命令行执行命令对应的 命令行简称
 
这里需要说的是,如果创建出现错误,线composer update 一下。
 
2. 创建后,会在app/command/下有对应命令类名称文件,是自动创建的包括文件夹
默认文件代码如下
<?php
declare (strict_types = 1);
 
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;
 
class Bdsitemap extends Command
{
    protected function configure()#这里是配置相关
    {
        // 指令配置
        $this->setName('bdsitemap')
            ->setDescription('the bdsitemap command');
    }
 
    protected function execute(Input $input, Output $output)# 这里是命令执行内容
    {
        // 指令输出
        $output->writeln('这里是thinkphp command bdsitemap 输出 ');# 这里是命令输出,我做了命令内容修改
    }
}
 
3. 增加 命令行command 执行配置文件,在 config/console.php中
原来默认:
return [
    // 指令定义
    'commands' => [
    ],
];
增加上述我们自定义的命令
<?php
return [
    'commands' => [
'bdsitemap' => 'app\command\Bdsitemap',# 这里的主键是我们自定义的命令简称,后面是对应的类名称
    ]
];
运行命令行 php think,看自定义bdsitemap 是否在列表中了
Available commands:
  bdsitemap         the bdsitemap command
  build             Build App Dirs
  clear             Clear runtime file
....
4. thinkphp6 运行command 命令行命令
在命令行执行
php think bdsitemap
命令行输出 
这里是thinkphp command bdsitemap 输出 
 
以上就是thikphp 命令行执行command 相关操作

学习www.网for站asp制.cn作

·上一篇:thinkphp 输出xml >>    ·下一篇:laravel安装redis >>
推荐文章
最新文章