美文网首页
Tp5·请求数据获取

Tp5·请求数据获取

作者: 三米板 | 来源:发表于2020-03-25 19:10 被阅读0次

    请求的数据,我们可以使用两个助手方法
    request()
    input()

    input()

    是一个数组,这包含了请求中的get和post的参数列表

    request()

    是一个对象,它包含了一个http请求所有的数据。其中包括get & post的数据。包括seesion和cookie等所有数据。

    object(think\Request)[2]
      protected 'method' => string 'GET' (length=3)
      protected 'domain' => null
      protected 'url' => string '/admin/news/index.html?page=5' (length=29)
      protected 'baseUrl' => null
      protected 'baseFile' => string '/index.php' (length=10)
      protected 'root' => string '' (length=0)
      protected 'pathinfo' => string 'admin/news/index.html' (length=21)
      protected 'path' => string 'admin/news/index' (length=16)
      protected 'routeInfo' => 
        array (size=0)
          empty
      protected 'env' => null
      protected 'dispatch' => 
        array (size=2)
          'type' => string 'module' (length=6)
          'module' => 
            array (size=3)
              0 => string 'admin' (length=5)
              1 => string 'news' (length=4)
              2 => string 'index' (length=5)
      protected 'module' => string 'admin' (length=5)
      protected 'controller' => string 'News' (length=4)
      protected 'action' => string 'index' (length=5)
      protected 'langset' => string 'zh-cn' (length=5)
      protected 'param' => 
        array (size=1)
          'page' => string '5' (length=1)
      protected 'get' => 
        array (size=1)
          'page' => string '5' (length=1)
      protected 'post' => 
        array (size=0)
          empty
      protected 'request' => 
        array (size=0)
          empty
      protected 'route' => 
        array (size=0)
          empty
      protected 'put' => null
      protected 'session' => 
        array (size=0)
          empty
      protected 'file' => 
        array (size=0)
          empty
      protected 'cookie' => 
        array (size=0)
          empty
      protected 'server' => 
        array (size=35)
          'USER' => string 'liuguoyan' (length=9)
          'HOME' => string '/Users/liuguoyan' (length=16)
          ................
          'PATH_INFO' => string '/admin/news/index.html' (length=22)
      protected 'header' => 
        array (size=11)
          'host' => string 'news.com' (length=8)
          ................
          'content-type' => string '' (length=0)
          'content-length' => string '' (length=0)
      protected 'mimeType' => 
        array (size=12)
          'xml' => string 'application/xml,text/xml,application/x-xml' (length=42)
          ................
      protected 'content' => null
      protected 'filter' => string '' (length=0)
      protected 'bind' => 
        array (size=0)
          empty
      protected 'input' => string '' (length=0)
      protected 'cache' => null
      protected 'isCheckCache' => null
      protected 'mergeParam' => boolean true
    

    request()的数据比较多,我们简略来写了一些。

    我们看到request()中,有param & get & post的数组
    所以我们可以使用request()->param() & request()->get() & request()->post()来获取到数据。

    判断 param & get &post中某个值是否存在

    如果要判断数组中的某个值是否存在,我们不可以直接
    if(arr['key']) 我们要使用 empty()函数来做判断 if(!empty(arr['key']))

    if(!empty($data['page'])){
                echo $data['page'];
            }else{
                echo "no param.page" ; 
            }
    

    相关文章

      网友评论

          本文标题:Tp5·请求数据获取

          本文链接:https://www.haomeiwen.com/subject/iwixuhtx.html