tp5控制器内调用其他控制器方法并传参

//请求的主要内容
        $info = [
            $this->location['province'],
            $this->location['city'],
            $this->location['district']
        ];

        dump(action('api/agent' , $info));
\\被请求的控制器
<?php

namespace app\h5\controller;
use think\Controller;
class Api extends Controller{
    public function agent($province,$city,$district = ''){
        //dump(input('province'));
        /*$province = input('province');
        $city = input('city');
        $district = input('district');
        $lat = input('lat');
        $lng = input('lng');*/
        $where = "(province='".$province ."' and city='" . $city . "' and type = 2) or (province='" . $province . "' and city='" . $city . "' and area='" .$district . "' and type=3)";
        $res = db('agent')->where($where)->select();
//        return json($res);
        return $res;
    }
//
}

需要注意的是,请求的地方一定要传一维的参数,并且在被请求的控制器里面做绑定,绝对不能传二维参数

还看到另一种调用的方法(没有测试过,不知道能不能用):

//1.另一个控制器PayController在数据库中没有表  

  public function Confirm_order()
    {
        $a=new PayController();
        $b=$a->balance(1);
        echo $b;

        die;

  }

手册地址:http://www.kancloud.cn/manual/thinkphp5/144731
看手册,有个助手函数action(用法和R,A类似)。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值