//请求的主要内容
$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类似)。