Home >Backend Development >PHP Tutorial >CI framework, source code one-time judgment method to obtain post (get) data whether a certain field value is empty, cipost_PHP tutorial

CI framework, source code one-time judgment method to obtain post (get) data whether a certain field value is empty, cipost_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:52:401216browse

CI framework, source code one-time judgment method to obtain post (get) data whether a certain field value is empty, cipost

1. The following is the CI framework

1. Put all the fields to be received in the array

Example:

I want to receive: id, name, age, mobile and other fields

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

2. Just make a for loop judgment

<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>);

2. Source code judgment method (no more nonsense, go directly to the code)

<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>);

Conclusion:

In fact, both the CI framework and the source code can use the source code method (2), but in order to verify the security, only the first solution is used. The other methods called above are built-in with PHP. I don’t understand which method. You can check the PHP help documentation (the master ignores it)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1125997.htmlTechArticleCI framework, the source code determines at one time whether a certain field value is empty when obtaining post (get) data. cipost 1. The following is the CI framework 1. Put all the fields to be received in the array. Example:...
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