input - kouji6309/SingleMVC GitHub Wiki

說明

取得輸入的資料。SingleMVC::input 的別名。


原型

input(mixed $key = null, string $type = null) : mixed

參數

  • key

    索引名稱。如果未指定,將傳回目前請求方法中的所有資料。

  • type

    輸入種類。如果未指定,將使用目前請求方法中的資料。
    有效值:getpostputdeleteheadconnectoptionspatchfile

回應

  • 字串/陣列:符合 keytype 的內容。
  • null:找不到資料。

應用

GET 請求中取得索引為 q 的資料

public function index() {
    $query = input('q');
}

GET 請求中取得索引為 dataname 的資料

public function indext() {
    $name = input(['data', 'name']);
}

POST 請求中取得網址中索引為 q 的資料 (REST 用法參考這裡)

public function index_post() {
    $query = input('q', 'get');
}

POST 請求中取得上傳的檔案

public function index_post() {
    $files = input('file');
}

PUT 請求中取得輸入的資料

public function index_put() {
    $data = input();
}

注意

框架會處理輸入資料後並儲存於內部並在呼叫 input 時傳回資料,因此在框架執行後(如控制器或模組內)修改 $_GET$_POST$_FILES等變數,並不會影響 input 的傳回結果。

⚠️ **GitHub.com Fallback** ⚠️