博主信息
博文 14
粉丝 0
评论 0
访问量 18516
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
Request 获取参数
依然很m丶的博客
原创
2303人浏览过

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"
}



本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学