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/phpjyz/5,在控制器中调用如下
    echo $this->uri->segment(3);//输出phpjyz
    echo $this->uri->segment(4);//输出5
    echo $this->uri->segment(1);//welcome
     
    值得注意的是,在控制器中使用$_GET['phpjyz']是得不到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/phpjyz
    这里传入参数的顺序不能颠倒。
     
    获取post数据
    在CI控制其中可以直接使用PHP中的$_POST['key']来获取post数据;
     
    另外CI还封装了一个Input类,里面提供post方法来获取post提交过来的数据。
    $this->input->post('key');
  • 相关阅读:
    申论1
    why factory pattern and when to use factory pattern
    jvm的字符串池
    is assembler instruction and machine instuction atomic
    jvm本身的多线程机制
    final
    java类的加载
    path和classpath的用途
    jar -cmf file1 file2 file3命令
    MANIFEST.MF中的MF是什么意思
  • 原文地址:https://www.cnblogs.com/kenshinobiy/p/4280768.html
Copyright © 2011-2022 走看看