6——ThinkPhp中的请求:

<?php
namespace app\index\controller;
use think\console\Input;
use think\Controller;
use think\Db;
use think\Request;

class Index2 extends Controller
{
    public function index($name="张三")
    {
       // return '<style type="text/css">*{ padding: 0; margin: 0; } .think_default_text{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:)</h1><p> ThinkPHP V5<br/><span style="font-size:30px">十年磨一剑 - 为API开发设计的高性能框架</span></p><span style="font-size:22px;">[ V5.0 版本由 <a href="http://www.qiniu.com" target="qiniu">七牛云</a> 独家赞助发布 ]</span></div><script type="text/javascript" src="https://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script><script type="text/javascript" src="https://e.topthink.com/Public/static/client.js"></script><think id="ad_bd568ce7058a1091"></think>';
        $data=Db::name('users')->find();
        $this->assign('data',$data);
        $this->assign('name',$name); //assign:分派;选派
        return $this->fetch(); //fetch:抵达,到达
    }
    public function index2(){
        //获取当前的url:
        $request=Request::instance();
        echo 'request请求的url:'.$request->url().'<br/>';

        echo "this里面使用的request:".$this->request->url().'<br/>';

        //请求中绑定的数据:
        $this->request->bind('user_name','张三111');
        echo "绑定的数据内容:".$this->request->user_name.'<br/>';

        //请求的函数助手:
        echo request()->url()."<br/>";

        //获取请求信息:
        print_r(request()->param());
        echo "<br/>";
        echo '请求的参数name:'.request()->param('name');

        //获取请求信息的函数助手:
        print_r(\input());
        echo \input('name');

        //param支持变量的默认值和过滤:
        echo "<br/>";
        //请求中如果有name参数,就会取请求中的name参数,并转换为小写。如果没有就会取默认值,但不会进行小写转换:
        echo \request()->param('name','XIAOWANG','strtolower');echo "<br/>";

        echo "==========================request======================";
        echo "<br/>";
        echo "GET请求参数:";
        print_r(\request()->get());

        echo "<br/>";
        echo "GET请求参数中的age值:";
        print_r(\request()->get('age'));

        echo "<br/>";
        echo "POST请求参数:";
        print_r(\request()->post());
        echo "<br/>";
        echo "POST请求的age值:";
        print_r(\request()->post('age'));

        echo "<br/>";
        echo "COOKIE值:";
        print_r(\request()->cookie());
        echo "<br/>";
        echo "FILE请求的值:";
        print_r(\request()->file());

        echo "==========================INPUT======================";
        echo "<br/>";
        echo "input请求参数:";
        print_r(input('get.'));

        echo "<br/>";
        echo "GET请求参数中的age值:";
        print_r(input('get.age'));

        echo "<br/>";
        echo "POST请求参数:";
        print_r(input('post.'));
        echo "<br/>";
        echo "POST请求的age值:";
        print_r(input('post.age'));;

        echo "<br/>";
        echo "COOKIE值:";
        print_r(input('cookie.'));
        echo "<br/>";
        echo "FILE请求的值:";
        print_r(input('file.'));

        echo "====================request其他参数========================";
        echo "<br/>";
        echo "请求方法:".\request()->method();
        echo "访问IP:".\request()->ip()."<br/>";
        echo "是否Ajax请求:".(\request()->isAjax()?"是":"否")."<br/>";
        echo "当前域名:".\request()->domain()."<br/>";
        echo "当前入口文件:".\request()->baseFile()."<br/>";
        echo "包含域名的完整URL地址:".\request()->url(true)."<br/>";
        echo "URL地址的参数信息:".\request()->query()."<br/>";
        echo "当前URL地址,不包含QUERY_STRING".\request()->baseUrl()."<br/>";
        echo "URL地址中的pathinfo信息:".\request()->pathinfo()."<br/>";
        echo "URL地址的后缀信息:".\request()->ext()."<br/>";

        echo "========================request当前模块/控制器/操作信息======================="."<br/>";
        echo "模块:".\request()->module()."<br/>";
        echo "控制器:".\request()->controller()."<br/>";
        echo "方法:".\request()->action();
    }
}

  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值