5ucms论坛
标题:
5 thinkphp的请求 request tp5的请求教程
[打印本页]
作者:
admin
时间:
2019-5-28 12:46
标题:
5 thinkphp的请求 request tp5的请求教程
请求request: $_GET $_POST $_REQUEST $_COOKIE $_FILES
响应response: json xml redirect view模板输出 $this->success 或 $this->error
函数助手 param() request() url() input()
use think\Request;
class Index4 extends Controller
{
public function hello(){
//不继承Controller类时使用
$request = Request::instance(); //实例化
echo $request->url(); //获取当前URL地址 不含域名
echo "<br/>";
//正常继承Controller类时直接即可
echo $this->$request->url(); //获取当前URL地址 不含域名
echo "<br/>";
echo $this->$request->bind('user_name','邱嵩松'); //动态绑定属性,后面可以直接用
echo "<br/>";
echo $this->$request->user_name; //其他控制器中可以直接取出使用
echo "<br/>";
echo request()->url(); //方了简洁方便可以用 函数助手
echo "<br/>";
/**请求变量信息**/
print_r($request->param()); //获取所有参数
echo "<br/>";
echo $request->param('name'); //获取一个参数
echo "<br/>";
print_r(input()); //方了简洁方便可以用 函数助手
echo "<br/>";
echo input('name'); //获取一个参数
echo "<br/>";
/**param方法获取变量,默认值,过滤方法**/
print_r($request->param('name','tom','strtolower')); //获取name的参数,如果没有默认为tom,获取到的值设置为小写
echo "<br/>";
/**获取指定参数**/
echo "=======request========<br/>"
echo 'GET参数:';
print_r($request->get()); echo '<br/>'
echo 'GET参数:name';
print_r($request->get('name')); echo '<br/>'
echo 'POST参数:name';
print_r($request->post('name')); echo '<br/>'
echo 'cookie参数:name';
print_r($request->cookie('name')); echo '<br/>'
echo '上传文件信息:image:';
print_r($request->file('image')); echo '<br/>'
/**input**/
echo "=======input========<br/>"
echo 'GET参数:';
print_r(input('get.'); echo '<br/>'
echo 'GET参数:name';
print_r(input('get.name'); echo '<br/>'
echo 'POST参数:name';
print_r(input('post.name'); echo '<br/>'
echo 'cookie参数:name';
print_r(input('cookie.name'); echo '<br/>'
echo '上传文件信息:image:';
print_r(input('file.image'); echo '<br/>'
echo "=======其他参数========<br/>"
echo '请求方法:'.$request->method().'<br/>';
echo '访问IP:'.$request->ip().'<br/>';
echo '是否Ajax请求:'.$request->isAjax()?"是":"否".'<br/>';
echo '当前域名:'.$request->domain().'<br/>';
echo '当前入口文件:'.$request->baseFile().'<br/>';
echo '包含域名的完整地址:'.$request->url(true).'<br/>';
echo 'URL地址的参数信息:'.$request->query().'<br/>';
echo '当前URL地址 不含QUERY_STRING:'.$request->baseUrl().'<br/>';
echo 'URL地址中的pathinfo信息:'.$request->pathinfo().'<br/>';
echo 'URL地址中的后缀信息:'.$request->ext().'<br/>';
echo "=======request 当前模块、控制器、操作信息========<br/>"
echo '模块:'.$request->module().'<br/>';
echo '模块:'.$request->controller().'<br/>';
echo '方法:'.$request->action().'<br/>';
}
}
复制代码
欢迎光临 5ucms论坛 (http://bbs.5ucms.com/)
Powered by Discuz! X3.2