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

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

WBOY
WBOYOriginal
2016-06-13 08:40:09966browse

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 帮助文档(大神忽略)

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn