Blogger Information
Blog 14
fans 0
comment 0
visits 16102
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Request 获取参数
依然很m丶的博客
Original
2040 people have browsed it

Request 获取参数

<?php
namespace app\index\controller;
//use think\Controller;
use think\Request;
class Index /*extends Controller*/
{
    public function index($id,$name)
    {
    return '$id='.$id.',$name='.$name;
    }
    public function demo($id='',$name='')
    {
        $request = Request::instance();
        dump($request->param('na'));
    }
}

获取各项操作/参数

<?php
namespace app\index\controller;
//use think\Controller;
use think\Request;
class Index /*extends Controller*/
{
    public function index($id,$name)
    {
    return '$id='.$id.',$name='.$name;
    }
    public function demo($id='',$name='',$age='')
    {
        $request = Request::instance();
        dump($request->domain());    //获取域名
        dump($request->url());       //不包含域名
        dump($request->url(true));   //包含域名
        dump($request->pathinfo());  //包含后缀 .html
        dump($request->path());      //不包含后缀
        dump($request->ext());       //返回后缀  .html
        dump($request->module());    //模块
        dump($request->controller());//返回控制器
//        $request->action('text');    //更改操作
        dump($request->action());    //获取错做方法
        dump($request->method());    //获取请求类型
        dump($request->ip());        //获取IP
        dump($request->only('id'));   //只获取ID
        dump($request->except('id')); //除了ID
    }
}

返回结果:

string(18) "http://www.tp5.com"
string(39) "/index/index/demo/id/12/name/luo/age/22"
string(57) "http://www.tp5.com/index/index/demo/id/12/name/luo/age/22"
string(38) "index/index/demo/id/12/name/luo/age/22"
string(38) "index/index/demo/id/12/name/luo/age/22"
string(0) ""
string(5) "index"
string(5) "Index"
string(4) "demo"
string(3) "GET"
string(9) "127.0.0.1"
array(1) {
  ["id"] => string(2) "12"
}
array(2) {
  ["name"] => string(3) "luo"
  ["age"] => string(2) "22"
}



Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post