CI框架获取post和get参数 CodeIgniter
2016-02-16 10:13
501 查看
请参考: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');
相关文章推荐
- 解析sql语句中left_join、inner_join中的on与where的区别
- 配置在.properties文件中的常量,
- 安卓中IOC框架中所用的动态代理的应用。
- springMVC两种方式实现多文件上传及效率比较
- 面试题—链表操作2
- 网络安全领域最具代表性的75个安全工具
- Cron 表达式详解和案例
- crontab 相关
- tar -xzvf .tar.gz
- 解决提交按钮在IE浏览器正常在360浏览器不可用
- lua语言介绍
- springMvc框架系统项目
- java中equals和等号(==)的区别浅谈
- 实现电子时钟效果
- 优美的 Python
- 认清Android Studio下的Gradle是什么
- EPC合同风险审核的若干重点问题
- C#面试题
- Java.io.File中的delete()方法和deleteOnExit()方法的区别
- SqlServer中循环和条件语句示例!