博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
php think命令用不了,自定义 PHP think 命令无法在命令类文件里面使用 Db 类
阅读量:4507 次
发布时间:2019-06-08

本文共 1231 字,大约阅读时间需要 4 分钟。

thinkPHP版本是5.0.14

输入 php think 在 Available commands: 下面能看到有housePost命令

Available commands:

build Build Application Dirs

clear Clear runtime file

help Displays help for a command

housePost 房源定时批量公布命令

list Lists commands

这是命令行类,直接echo输出没有问题,但是模型或者Db类就会报PDO的错误

namespace app\command\controller;

use think\console\Command;

use think\console\Input;

use think\console\Output;

use think\console\input\Argument;

use app\index\model\HouseVillage;

use think\Db;

class HousePost extends Command

{

protected function configure()

{

$this->addArgument('houseId',Argument::REQUIRED); #必须参数

$this->addArgument('date',Argument::OPTIONAL); #可选参数

$this->setName('housePost')->setDescription('房源定时批量公布命令');

}

protected function execute(Input $input, Output $output)

{

$houseId = $input->getArgument('houseId');

$date = $input->getArgument('date');

#逻辑代码

$result = HouseVillage::all();

// $result = Db::table('house_village')->select();

#输出代码

$output->writeln("HousePost:houseId=".json_encode($result));

// $output->writeln("TestCommand:test2=".json_encode($date));

}

}

调用模型后返回PDO的错误

xxxxxx@DESKTOP-UNTNOIG:/....../www/......../code/lhzs_back$ php think housePost 定时测试任务

[PDOException]

could not find driver

php.ini里面PDO肯定是打开的

51115ed8aaa36e469808c72372d16101.png

有熟悉thinkPHP命令行的朋友知道怎么解决吗?

转载地址:http://thats.baihongyu.com/

你可能感兴趣的文章
多线程概述
查看>>
Linux_ubuntu命令-用户、权限管理
查看>>
Knowladge_网站学习_RSS 学习
查看>>
TCP/IP,Web世界的基本规则
查看>>
c++ 子类构造函数初始化及父类构造初始化
查看>>
Analysis on Human Various Emotional Expression
查看>>
DataGridView DataGridViewCheckBoxColumn编辑时实时触发事件
查看>>
SignalR---服务端
查看>>
PlayerPrefs存储Vector3等结构数据
查看>>
LightOJ - 1422 Halloween Costumes (区间DP)
查看>>
Dubbo架构设计详解
查看>>
谁终将点燃闪电,必长久如云漂泊
查看>>
小诗句集萃四
查看>>
软件之美: 易用性设计的目标及准则
查看>>
异步回调,事件,线程池与协程
查看>>
matlab函数:c2d离散化函数(待完善)
查看>>
java并发多面性
查看>>
TFS 测试用例导入、导出工具
查看>>
java -jstack
查看>>
C#中线程调用带有参数的方法
查看>>