zoukankan      html  css  js  c++  java
  • CI框架获取post和get参数 CodeIgniter

    请参考:CI文档的输入类部分:
    
    $this->input->post() 
    $this->input->get()
    
    -----------------------------------------------------------------------------------------------------------------------
    
    本文主要介绍在CodeIgniter框架中如何获取get和post参数。
    获取get数据
    在PHP主流的框架中,CI中url的pathinfo传递参数是一个特殊情况,它没有使用传统pathinfo的'c/m/key/value'
    这种模式,而是在URI类中封装了segment这个方法,假设uri为/index.php/welcome/index/phptest/5,在控制器中调用如下
      
      echo $this->uri->segment(3);//输出phptest
      echo $this->uri->segment(4);//输出5
      echo $this->uri->segment(1);//welcome 
      值得注意的是,在控制器中使用$_GET['phptest']是得不到5这个值的。 另外,针对get参数还可以在控制的动作(方法)加参数,例如
      class Welcome extends CI_Controller {
        public function index($id=0, $name=''){
          echo $id.$name;
        }
      } 
     上面在index方法里加了两个参数$id和$name,有默认值表示该参数可选,uri的格式如下   
    index.php/welcome/index/5/phptest
    
    
    
     这里传入参数的顺序不能颠倒。 获取post数据 在CI控制其中可以直接使用PHP中的$_POST['key']来获取post数据; 另外CI还封装了一个Input类,里面提供post方法来获取post提交过来的数据。   
    $this->input->post('key');

     

  • 相关阅读:
    hdu 2222 Keywords Search 模板题
    AC自动机 (模板)
    7. 通过鼠标右键改变视角
    NGUI所见即所得之UIAtlasMaker , UIAtlas (2)
    6. 通过鼠标滑轮控制“镜头远近”
    5. Unity脚本的执行顺序
    4. 在Inspector面板中显示类中变量+ 拓展编辑器
    NGUI 的使用教程与实例(入门)(1 )
    1. 通过移动鼠标旋转摄像机观察模型
    C#面试题
  • 原文地址:https://www.cnblogs.com/qhorse/p/5191910.html
Copyright © 2011-2022 走看看