首页  >  文章  >  后端开发  >  CI框架,源代码一次性判断获取post(get)数据是否有某个字段值为空方法,cipost_PHP教程

CI框架,源代码一次性判断获取post(get)数据是否有某个字段值为空方法,cipost_PHP教程

WBOY
WBOY原创
2016-07-12 08:52:401187浏览

CI框架,源代码一次性判断获取post(get)数据是否有某个字段值为空方法,cipost

一、以下是CI框架

1、把所有的要接收的字段放在数组中

  例:

    我要接收:id,name,age,mobile 等字段

<span>$req</span> = <span>array</span>('id','name','age','mobile');

 

2、for循环判断即可

<span>1</span> <span>for</span>(<span>$i</span> = 0;<span>$i</span> < <span>count</span>(<span>$req</span>);<span>$i</span> ++<span> ){    
</span><span>2</span>     <span>$j</span> = <span>$this</span>->load->get_post(<span>$req</span>[<span>$i</span>],<span>true</span><span>);
</span><span>3</span>     <span>if</span>(<span>empty</span>(<span>$j</span><span>))
</span><span>4</span>             <span>exit</span>(<span>$req</span>[<span>$i</span>].' 为空'<span>);
</span><span>5</span>     <span>$data</span>[<span>$i</span>] = <span>$j</span><span>;
</span><span>6</span> <span>}
</span><span>7</span>     <span>print_r</span>(<span>$data</span>);

 

二、源代码判断方法(就不废话了,直接上代码)

<span>$req</span> = <span>array</span>('id','name','age','mobile'<span>);
</span><span>for</span>(<span>$i</span> = 0;<span>$i</span> < <span>count</span>(<span>$req</span>);<span>$i</span> ++<span> ){    
     </span><span>$j</span> = <span>$_POST</span>[<span>$req</span>[<span>$i</span><span>]];
     </span><span>if</span>(<span>empty</span>(<span>$j</span><span>))
             </span><span>exit</span>(<span>$req</span>[<span>$i</span>].' 为空'<span>);
     </span><span>$data</span>[<span>$i</span>] = <span>$j</span><span>;
}
     </span><span>print_r</span>(<span>$data</span>);

 

结束语:

  其实CI框架与源代码都可以用源代码这种方法(二),但是为了验证安全性,使用第一种方案而已,以上调用的其他方法是php自带的,哪个方法不懂,可以查一下PHP 帮助文档(大神忽略)

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1125997.htmlTechArticleCI框架,源代码一次性判断获取post(get)数据是否有某个字段值为空方法,cipost 一、以下是CI框架 1、把所有的要接收的字段放在数组中 例:...
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn