リクエストclass Req
ユーザーからの入力に関する操作を担当するクラスです。
GET / POSTなどのパラメータの受け取り
<?php
// $_POST['user_name']を取り出します。
$user_name = Req::post('user_name');
// $_POST['agree']を取り出します。値がないときは、`false`(第2引数)を返します。
$user_agree = Req::post('agree', false);
// $_GET['page']を取得します。値がないときは`1`を返します
$page_no = Req::get('page', 1);
JSON POSTの受け取り
Backbone.jsのようなJSONをpostするクライアントサイドライブラリに有効です。
<?php
$body = Req::json();
// JSON内の特定の要素を取り出す
$user_name = Req::json('user_name');
// 生POSTデータを取得 (`php://input`の内容を取得)
$rawBody = Req::rawBody();