本地执行TP5框架的方法

1配置环境变量
在这里插入图片描述
例如我的环境变量 C:\Users\Administrator\AppData\Roaming\Composer\vendor\bin;F:\PhpStudy\PHPTutorial\php\php-7.1.13-nts\php.exe(注意用;隔开)

或者cmd进入;F:\PhpStudy\PHPTutorial\php\php-7.1.13-nts

2再app新建一个command文件夹,新建一个test.php文件,注意看图片
在这里插入图片描述
代码如下
`<?php
namespace app\command;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Db;

class Test extends Command
{
protected function configure()
{
$this->setName(‘test’);//定义命令的名字
}

protected function execute(Input $input, Output $output)
{
    set_time_limit(0);
    $array_brand = [];
    $brandInfo   = Db::name('StoreCommunityBrands')->field('user_id,id')->select();
    foreach ($brandInfo as $v) {
        $array_brand[$v['id']] = $v['user_id'];
    }
    $userInfo = Db::name('StoreUser')->field('id')->select();
    foreach ($userInfo as $v) {
        echo "\n";
        echo $v['id'];
        $brand_id = $this->getPid($v['id'], $array_brand);
        if($brand_id==null || $brand_id==0){
            $brand_id = 1;
        }
        //写入社群
        Db::name('StoreUser')->where('id',$v['id'])->update(['brand_id'=>$brand_id]);
    }
    echo "<结束>";exit;
}

public function getPid($id, $array_brand)
{
    $result = Db::name('StoreUser')->field('reference')->where('id', $id)->find();
    if ($result){
        if (in_array($id,$array_brand)) {
            $brand_id = array_search($id, $array_brand);
            return $brand_id;
        }elseif(in_array($result['reference'], $array_brand)){
            $brand_id = array_search($result['reference'], $array_brand);
            return $brand_id;
        }
        $this->getPid($result['reference'],$array_brand);
    }else{
        return 1;
    }
}

}
`

//代码可以自己更改

execute()这个方法是执行的页面逻辑

3在command里面加入你的命名控空间在这里插入图片描述

4命令行
在这里插入图片描述
进入到你的项目
然后看你的方法是否已经进入
在这里插入图片描述

之后就可以 用 php think test 命令,执行你的业务逻辑了
在这里插入图片描述

不懂的同学可以加我v 17705921980 咨询(互帮互助)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值