Blink 中 \blink\http\Request
承載了所有的用戶輸入,我們可以方便的獲取請求頭、URL參數(shù)、請求數(shù)據(jù)等信息:
use \bink\core\Object;
use \bink\http\Request;
class Controller extends Object
{
public function index(Request $request)
{
$type = $request->params->get('type'); // 獲取 Query 參數(shù) type
$params = $request->params->all(); // 獲取所有 Query 參數(shù)
$name = $request->body->get('name'); // 獲取 Request Body 的 name 參數(shù)
$body = $request->body->all(); // 獲取整個 Request Body
}
}
更多有用的方法請參考 \blink\http\Request
的源代碼及注釋。
Blink 中,Action 方法可以直接返回數(shù)據(jù)給客戶端,支持返回字符串和數(shù)組類型:
use \bink\core\Object;
use \bink\http\Request;
class Controller extends Object
{
public function action1()
{
return 'this is a string'; // 直接返回字符串,原樣輸出到客戶端。
}
public function action2()
{
return [
'name' => 'foo' // 返回數(shù)組,json_encode 后輸出到客戶端
]
}
}
另外,Request 和 Response 的中間件架構(gòu)也在計劃中,未來會提供更多的方式來對輸入輸出的數(shù)據(jù)進行格式化。
更多建議: