thinkphp模拟请求和参数绑定

2019-04-14 12:44发布

thinkphp模拟请求和参数绑定

一、总结

1、网页传过来的参数是可以修改的:get或者post等方式 传过来的参数是可以修改的  dump($request->get(['id'=>20]));  //数组 2、各种请求类型也是可以判断的: dump($request->isMobile()); 3、模拟ajax请求http://www.tp.com/index.php/index/index/type?_ajax=10 4、伪静态是什么以及作用? 5、参数banding直接把页面传过来的参数用函数的形参接收,而不用$request      

二、知识点

11、更改变量

         // 地址栏访问 http://www.tp.com/index.php/Index/Index/xiugai?id=10          dump($request->get('id'));  // 10          dump($request->get(['id'=>20]));  //数组            dump($request->get('id'));  // 20    

12、请求类型判断

         1、系统类                      // 判断是否是get请求                    dump($request->isGet());                    // 判断是否是手机端                    dump($request->isMobile());            2、系统函数                    dump(request()->isGet());                    dump(request()->isMobile());    

13、模拟put、delete请求

         1、使用                     
                           

                                     User:                                                                                                       

                           

                                     Pass:                                                                 

                           

                                                                

                  
           2、注意                    1、表单的请求类型必须是post                      2、需要设置隐藏域传递模拟请求类型  

14、模拟ajax请求和PJAX请求

         1、模拟ajax请求                    http://www.tp.com/index.php/index/index/type?_ajax=10            2、模拟pjax请求                    http://www.tp.com/index.php/index/index/type?_pjax=10    

15、伪静态

         1、作用                    1) URL伪静态通常是为了满足更好的SEO效果                    2) 为了网站的安全            2、修改伪静态                    在配置文件中进行修改                      'url_html_suffix'        => 'shtml',            3、获取当前的伪静态后缀                    $request->ext();    

16、参数绑定

         1、使用                    public function banding($id,$name="admin"){                            dump($id);                        dump($name);                    }                      http://www.tp.com/index.php/index/index/banding/id/1/name/user            2、注意                    1、参数绑定的个数,少于地址栏参数的个数                      2、参数绑定的名字,必须和地址栏参数名字一一对应                      3、参数绑定可以设置默认值