php传参app,Thinkphp5.0 cli 传参

application/command.php 代码如下 返回一个cli的控制器

return ['app\command\test'];

application/command/test.php 代码如下 加注释

use think\console\Command;

use think\console\Input;

use think\console\Output;

class test xtends Command

{

//初始化命令 以及命令配置

protected function configure()

{

// 这里的test就是命令行think后面的参数 action 方法名 parameter 参数 (url模式)uid=42#file=ccc uid为用户名 file为做进度查询的MD5文件名

$this->setName('test')->addArgument('action')->addArgument('parameter')->setDescription('这里的test就是命令行think后面的参数 action 方法名 parameter 参数 (url模式)uid=42#file=ccc uid为用户名 file为做进度查询的MD5文件名');

}

//命令执行方法

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

{

//接收方法名 和 参数

$myparme = $input->getArguments();

$action = $myparme['action'];

$parameter = $myparme['parameter'];

//参数转义解析

$arguments = $this->ParSing($parameter);

//执行对应的方法

$info = $this->$action($arguments);

//输出返回值

$output->writeln($info);

}

//代码解析(urlget传参模式)

protected function ParSing($parameter){

//c=d#a=b#rrr=666

$parameter_array = array();

$arry = explode('#', $parameter);

foreach ($arry as $key => $value) {

$zzz = explode('=',$value);

$parameter_array[$zzz[0]] = $zzz[1];

}

return $parameter_array;

}

//测试方法

public function index($data){

echo $data['uid'];

echo $data['file'];

}

}

切换到项目目录

php think test index uid=6#file=ccc

想知道原理的

男的自己看

use think\console\Command;

use think\console\Input;

use think\console\Output;

这3个文件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值