zoukankan      html  css  js  c++  java
  • 8.Yii2.0框架控制器接收get.post数据

    8.Yii2.0框架控制器接收get.post数据

    一.get传参

     1 <?php
     2 /**
     3  * Created by Haima.
     4  * Author:Haima
     5  * QQ:228654416
     6  * Date: 2018/8/23
     7  * Time: 5:36
     8  */
     9 
    10 namespace appcontrollers;
    11 
    12 use yiiaseController;
    13 
    14 class HomeController extends Controller
    15 {
    16     public function actionIndex(){
    17         $request = Yii::$app->request;
    18         //获取get传参
    19         $id = $request->get('id',1); //默认不传参时为1
    20         dump($id);
    21         //获取post传参
    22 //        $username = $request->post('username','xiaoli'); //默认不传参时为xiaoli
    23 //        dump($username);
    24 ////        return $this->render('index');
    25     }
    26 }

    get打印效果:

    http://yii.com/index.php?r=home/index&id=6 

    这里的index可以不要

    例:

    http://yii.com?r=home/index&id=6 

     

    二.post传参:

     1 <?php
     2 /**
     3  * Created by Haima.
     4  * Author:Haima
     5  * QQ:228654416
     6  * Date: 2018/8/23
     7  * Time: 5:36
     8  */
     9 
    10 namespace appcontrollers;
    11 
    12 use yiiaseController;
    13 
    14 class HomeController extends Controller
    15 {
    16     public function actionIndex(){
    17         $request = Yii::$app->request;
    18         //获取get传参
    19 //        $id = $request->get('id',1); //默认不传参时为1
    20 //        dump($id);
    21         //获取post传参
    22         $username = $request->post('username','xiaoli'); //默认不传参时为xiaoli
    23         dump($username);
    24 //        return $this->render('index');
    25     }
    26 }

     打印效果

    三.判断请求类型和用户IP:

     1 <?php
     2 /**
     3  * Created by Haima.
     4  * Author:Haima
     5  * QQ:228654416
     6  * Date: 2018/8/23
     7  * Time: 5:36
     8  */
     9 
    10 namespace appcontrollers;
    11 
    12 use yiiaseController;
    13 
    14 class HomeController extends Controller
    15 {
    16     public function actionIndex(){
    17         $request = Yii::$app->request;
    18         //获取get传参
    19 //        $id = $request->get('id',1); //默认不传参时为1
    20 //        dump($id);
    21         //获取post传参
    22 //        $username = $request->post('username','xiaoli'); //默认不传参时为xiaoli
    23         $get = $request->isGet; //判断get提交 返回 true/false
    24         $post = $request->isPost; //判断post提交 返回 true/false
    25         $ip = $request->UserIP; //获取用户IP
    26 
    27         vp($get);
    28         vp($post);
    29         vp($ip);
    30 //        return $this->render('index');
    31     }
    32 }

    打印效果:

    [Haima的博客] http://www.cnblogs.com/haima/
  • 相关阅读:
    nagios对windows流量的检测
    Zabbix中文使用手册
    SNMP的应用
    十大经典排序算法最强总结(含JAVA代码实现)
    各种排序算法总结和比较
    MyBatis的Insert操作详解
    MyBatis 返回insert操作主键
    MyBatis insert/delete/update 的返回值
    利用aopc创建schema失败
    neo4j开发自定义存储过程注意事项
  • 原文地址:https://www.cnblogs.com/haima/p/9521564.html
Copyright © 2011-2022 走看看