用户
 找回密码
 入住 CI 中国社区
搜索
查看: 2172|回复: 2
收起左侧

[HELP] 想实现自动循环获取input,get过来的数组信息

[复制链接]
发表于 2012-8-31 09:58:49 | 显示全部楼层 |阅读模式
   最近在最网站后台代码重构的时候,突然看到大量的
  $title_levelone = $this->input->post('title_levelone');
  $title_leveltwo = $this->input->post('title_leveltwo');
  $tag = $this->input->post('tag');
  $from = $this->input->post('from');
  $author = $this->input->post('author');
  $time = $this->input->post('time');
  $content = $this->input->post('content');
  ..............................
这一类没啥意义的重复性代码,就寻思着能不能实现一个自动循环获取客户端发来的input,get的数组信息呢?
因为我觉得input从本质的数据结构角度来看就是一个多维数组罢了。应该可以这样
$data = $this->input->post();
foreach($data as $key => $value)
{
      data['$key'] = $value;
}
...
传给模型进行crud处理

但是具体怎么实现还是不太清楚,也不知道行不行。
谁有更好的实现方法能赐教一下吗
发表于 2012-8-31 12:38:45 | 显示全部楼层
试一下 $this->input->post(NULL, TRUE);
或       $this->input->get(NULL, TRUE);
发表于 2012-9-1 09:22:39 | 显示全部楼层
楼上说的试过了,确定这样的用法行不通,你可以这样
$post = key($_POST);
foreach($post as $v)
{
   $v = filte($v);
   $temp[$v] = $this->input->post($v);
}
Print_r( $temp);

本版积分规则