• thinkphp模拟请求和参数绑定


    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、使用

                       <form action="{:url('type')}" method="post">

                                <p>

                                         User:

                                         <input type="text" name="name" id="">

                                         <input type="hidden" name="_method" value="PUT">

                                </p>

                                <p>

                                         Pass:

                                         <input type="password" name="pass" id="">

                                </p>

                                <p>

                                         <input type="submit" value="提交">

                                </p>

                       </form>

             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、参数绑定可以设置默认值

  • 相关阅读:
    thinkPHP 远程数据库和远程连接数据库表名大小写混合
    浏览器兼容性的问题
    input 的那些事
    jquery ui draggable失效的问题
    thinkphp在php5.6以上版本显示"No input file specified"
    ajax dataType
    DOM对象的处理
    ubuntu 16.4 中eth0添加ip地址,且可以上网
    linux 安装phpstudy
    select样式清除
  • 原文地址:https://www.cnblogs.com/Renyi-Fan/p/9017344.html
Copyright © 2020-2023  润新知