1. 程式人生 > >美國清華大學 IN The Du Jin Feng

美國清華大學 IN The Du Jin Feng

<?php     
   /*
    *Thinkphp3.2添加了一個I方法,取義Input,用來獲取前臺提交過來的資料。
    *下面來下I()方法的一些使用技巧:
    *I方法是放在了/ThinkPHP/Common/function.php之中

    */

    /**
     * 獲取輸入引數 支援過濾和預設值
     * 使用方法:
     * <code>
     * I('id',0); 獲取id引數 自動判斷get或者post
     * I('post.name','','htmlspecialchars'); 獲取$_POST['name']
     * I('get.'); 獲取$_GET
     * </code>
     * @param string $name 變數的名稱 支援指定型別
     * @param mixed $default 不存在的時候預設值
     * @param mixed $filter 引數過濾方法
     * @return mixed
     */
    function I($name,$default='',$filter=null) {
        if(strpos($name,'.')) { // 指定引數來源
            //判斷引數$name中是否包括.號
            list($method,$name) =   explode('.',$name,2);
            //如果包括.號將.號前後分隔,並且分別賦值給$method以及$name
        }else{ // 預設為自動判斷
            //如果沒有.號
            $method =   'param';
        }
        switch(strtolower($method)) {//將$method轉換為小寫
            //如果$method為get,則$input為$_GET
            case 'get'     :   $input =& $_GET;break;
            //如果$method為get,則$input為$_POST
            case 'post'    :   $input =& $_POST;break;
            //如果為put,則將post的原始資料轉引數給$input
            case 'put'     :   parse_str(file_get_contents('php://input'), $input);break;
            //如果是param
            case 'param'   :
                //判斷$_SERVER['REQUEST_METHOD']
                switch($_SERVER['REQUEST_METHOD']) {
                    //如果為post,則$input的內容為$_POST的內容
                    case 'POST':
                        $input  =  $_POST;
                        break;
                    //如果為PUT.則input的內容為PUT的內容
                    case 'PUT':
                        parse_str(file_get_contents('php://input'), $input);
                        break;
                    //預設為$_GET的內容
                    default:
                        $input  =  $_GET;
                }
                break;
            //如果$method為request,則$input為$_REQUEST
            case 'request' :   $input =& $_REQUEST;   break;
            //如果$method為session,則$input為$_SESSION
            case 'session' :   $input =& $_SESSION;   break;
            //如果$method為cookie,則$input為$_COOKIE
            case 'cookie'  :   $input =& $_COOKIE;    break;
            //如果$method為server,則$input為$_SERVER
            case 'server'  :   $input =& $_SERVER;    break;
            //如果$method為globals,則$input為$GLOBALS
            case 'globals' :   $input =& $GLOBALS;    break;
            //預設返回空
            default:
                return NULL;
        }
        /**
         * 到此為止,已經根據傳入的引數的需要(第一個引數.號前面的),把所有的變數都取到了。下面就是返回變數的內容了。
        **/
        //如果$name為空,也就是I()第一個引數的.號後面為空的時候
        if(empty($name)) { // 獲取全部變數
            //獲取到的變數$input全部複製給$data
            $data       =   $input;
            //array_walk_recursive — 對陣列中的每個成員遞迴地應用使用者函式
            //將$data的鍵值作為filter_exp函式的第一個引數,鍵名作為第二個引數
            //如果$data的鍵值中含有or或者exp這兩個字元,自動在後面加一個空格
            array_walk_recursive($data,'filter_exp');
            //判斷過濾引數是否有,如果有的話,就直接使用過濾方法,如果沒有的話,就使用配置中的過濾方法
            $filters    =   isset($filter)?$filter:C('DEFAULT_FILTER');
            if($filters) {
                $filters    =   explode(',',$filters);
                //將過濾引數中的每個方法都應用到$data中
                foreach($filters as $filter){
                    //將$data的每個值使用$filters過濾
                    $data   =   array_map_recursive($filter,$data); // 引數過濾
                }
            }
        }elseif(isset($input[$name])) { // 取值操作
            $data       =   $input[$name];
            is_array($data) && array_walk_recursive($data,'filter_exp');
            $filters    =   isset($filter)?$filter:C('DEFAULT_FILTER');
            if($filters) {
                $filters    =   explode(',',$filters);
                foreach($filters as $filter){
                    if(function_exists($filter)) {
                        $data   =   is_array($data)?array_map_recursive($filter,$data):$filter($data); // 引數過濾
                    }else{
                        $data   =   filter_var($data,is_int($filter)?$filter:filter_id($filter));
                        if(false === $data) {
                            return   isset($default)?$default:NULL;
                        }
                    }
                }
            }
        }else{ // 變數預設值
            $data       =    isset($default)?$default:NULL;
        }
        return $data;
    }














?>


相關推薦

美國清華大學 IN The Du Jin Feng

<?php         /*     *Thinkphp3.2添加了一個I方法,取義Input,用來獲取前臺提交過來的資料。     *下面來下I()方法的一些使用技巧:     *I方法是放在了/ThinkPHP/Common/function.php之中  

Package gtk+-3.0 was not found in the pkg-config search path

path 二進制 all 項目 有時 rpm fedora ack share 問題描述:   在fedora21系統上通過rpmbuild構建fcitx的二進制包時出現以上錯誤,經老程序員指點:“是相應的開發包沒有安裝” 解決辦法:   yum installl gtk3

HiHo1505:小Hi和小Ho的禮物(Meet-In-The-Middle + 組合數學)

整數 image namespace 多少 max using for 2種 100% 時間限制:10000ms 單點時限:1000ms 內存限制:256MB 描述 某人有N袋金幣,其中第i袋內金幣的數量是Ai。現在他決定選出2袋金幣送給小Hi,再選2袋金幣送給小H

TIME IN THE SUBWAY :GUESS NUM !

while switch guess number import java.util.Random;import java.util.Scanner;public class GuessNumber { public static void main(String[] args) {

ORA-23421: job number 225 is not a job in the job queue

conn uil bms delet ext roc erro declare dba_jobs   在對數據庫進行異機恢復之後,為了防止上面作業自動執行,擾亂正常業務系統,需要將測試庫上的作業和db_link進行刪除:但是使用sys用戶連接進去,刪除的時候報如下錯誤SQL

Namespace declaration statement has to be the very first statement in the script

ont 文件 space pac .net button php 解決 img php 中 Namespace declaration statement has to be the very first statement in the script 錯誤解決方

pycharm Zooming in the Editor

can span dialog eas open for .html rotate led https://www.jetbrains.com/help/pycharm/zooming-in-the-editor.html To enable changing font

Maven出現錯誤No plugin found for prefix 'jetty' in the current

jetty jpress Maven出現錯誤No plugin found for prefix ‘jetty‘ in the current project and in the plugin groups的問題解決只需在maven的setting.xml文件上加入如下節點:<pluginGr

解決Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 問題

== number keyword 解決辦法 class rac ref request 反斜杠 通過這裏的回答,我們可以知道: Tomcat在 7.0.73, 8.0.39, 8.5.7 版本後,添加了對於http頭的驗證。 具體來說,就是添加了些規則去限制HTTP頭

unity(使用了NGUI) 在Build時遇見DontSave but is included in the build

clu fonts 自動生成 tsa included image sources ext lag 錯誤提示: An asset is marked with HideFlags.DontSave but is included in the build:Asset: ‘L

Ubuntu 16.04 LTS 安裝libvips出現”Package vips was not found in the pkg-config search path”

arp dir exp export ron per gconf 部署 director 使用libvips來操作圖像,libvips的部署參考一個Node.js工程:https://github.com/lovell/sharp 在MAC下安裝很順利,到Linux環境下(

Can not find a java.io.InputStream with the name [downloadFile] in the invocation stack.

dex parameter work put 嚴重 efi open post onerror 1、錯誤描寫敘述八月 14, 2015 4:22:45 下午 com.opensymphony.xwork2.util.logging.jdk.JdkLogger error

[Preact] Use State and Props in the Component Render Function

cnblogs use method nic imp ima rop component end Preact offers, in addition to the regular component API from React, the ability to acces

Gym 101246D Fire in the Country(dfs求SG函數)

tor 我們 style sizeof std clas mem class == http://codeforces.com/gym/101246/problem/D 題意: 給定一個無向有環圖,大火從1點開始,每個時間點與它相鄰的點也將會著火,現在有兩個人輪流操作機

python version 2.7 required,which was not found in the registry

.html except http nco com name desc log all # # script to register Python 2.0 or later for use with win32all # and other extensions that

scale the service in the swarm

docker swarm 一旦你部署了一個服務到swarm集群中,你就可以使用docker命令行來伸縮擴容運行該服務的容器數量。運行在多個容器的一個服務叫做tasks 任務。$docker machine ssh manager1$ docker service scale <SERVICE-I

安裝第三方庫 報錯Python version 2.7 required, which was not found in the registry

try 三方庫 64位 req not 安裝 window 是我 found 我的Windows 系統是64位 這個問題有人說是註冊表沒有 ,手動註冊了一下就好了,但是我註冊的時候運行報錯。 那麽我的做法是: 刪掉本機所有安裝過得python , 1、 先進入控制面板,刪除

【二分】Petrozavodsk Winter Training Camp 2017 Day 1: Jagiellonian U Contest, Monday, January 30, 2017 Problem A. The Catcher in the Rye

什麽 不同 stdin n) clas sqrt ios 這份 std 一個區域,垂直分成三塊,每塊有一個速度限制,問你從左下角跑到右上角的最短時間。 將區域看作三塊折射率不同的介質,可以證明,按照光路跑時間最短。 於是可以二分第一個入射角,此時可以推出射到最右側邊界上的位

[WPF]The type name ‘App’ does not exist in the type '...'的問題

-s tar type quest blog alt http 再次 ges refer to: https://stackoverflow.com/questions/4480087/wpf-the-type-name-app-does-not-exist-in-the-

[LintCode] Number of Airplanes in the Sky

nis ems after tof multiple val count code ase Given an interval list which are flying and landing time of the flight. How many airplane