1.
<?php
namespace app\index\controller;
use think\Request;
class Index
{
public function index()
{
// $data = array(
// 'name' => 'nnnn',
// 'address' => 'china',
// );
// $code = 200;
// $msg = 'ok';
// return json(['data' => $data , 'code' => $code, 'message' => $msg]);
$request = Request::instance();
if ($request -> isGet()) {
echo "是get方法!";
}
if ($request -> isPost()) {
echo "是post方法!";
}
echo "请求方法:".$request -> method() . '<br/>';
echo "访问地址:".$request -> ip() . '<br/>';
echo "请求参数:";
dump($request -> param());
echo "请求参数:仅包含name,sex";
dump($request -> only(['name','sex']));
echo "请求参数:排除name";
dump($request -> except(['name']));
}
}
2.postman 测试结果: