input - kouji6309/SingleMVC GitHub Wiki
取得輸入的資料。SingleMVC::input 的別名。
input(mixed $key = null, string $type = null) : mixed
-
索引名稱。如果未指定,將傳回目前請求方法中的所有資料。
-
輸入種類。如果未指定,將使用目前請求方法中的資料。
有效值:get
、post
、put
、delete
、head
、connect
、options
、patch
、file
。
- 字串/陣列:符合
key
和type
的內容。 -
null
:找不到資料。
在 GET
請求中取得索引為 q
的資料
public function index() {
$query = input('q');
}
在 GET
請求中取得索引為 data
中 name
的資料
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
的傳回結果。