Request クラス

Request クラスは URI リクエストを処理します。Fuel は index.php 内で、ユーザーからの URI リクエストを処理するために同クラスを使用しています。また、HMVC コンテクストの中でリクエストを生成するためには、このクラスを使う必要があります。

forge($uri = null, $route = true)

forge メソッドは新しいリクエストオブジェクトを返します。

静的 はい
パラメタ
パラメタ 初期値 説明
$uri
null
リクエストされている URI。このパラメタが存在しない場合は、URI を見つけるために URI クラスが使われます。
$route
true
もし true であれば、渡された (passed) あるいは見つけだされた URI は Routing クラスで処理されます。もし経路 (ルート) が存在しないのであれば 404 が生成されます。もし非公開の URI をリクエストするのであれば、このパラメタには false を設定してください。
返り値 Fuel\Core\Request オブジェクト
// 管理コントローラーのログインメソッドのリクエストオブジェクトを生成する。
$request = Request::forge('admin/login');

// 注意:オブジェクトを生成するだけであって、リクエストを実行するわけではない!。

You can also use Request::forge() to forge a cURL or a SOAP request object.

execute($method_params = null)

The execute method executes a request and stores the resulting response in the request object to be used later.

静的 No
Parameters
Param Default Description
$method_params
null
An array of optional parameters to pass to the controller being called.
返り値 Fuel\Core\Request オブジェクト
// create and execute the request object for the admin controller, login method
$request = Request::forge('admin/login')->execute();

// pass an object to the login controller
$object = new Object();
$request = Request::forge('admin/login')->execute(array('object' => $object);

response()

response メソッドは、実行されたリクエストのレスポンスオブジェクトを取得します。

静的 No
パラメタ No
返り値 Fuel\Core\Response オブジェクト
// リクエストを実行し、レスポンスを取得し、それを表示する。
$response = Request::forge('admin/login')->execute()->response();
echo $response;

// リクエストオブジェクトには、出力取得の別の方法として __toString() メソッドが含まれている。
$output = Request::forge('admin/login')->execute();
echo $output;

params()

Returns an array of all named parameters in the route that triggered this request.

静的 No
パラメータ No
返り値 array
// get the list of named parameters
$params = Request::active()->params();

get_method()

Gets the request method.

静的 No
パラメータ none
返り値 Request method
// Get the request method on a forged request
$method = Request::main()->get_method();

set_method($method)

Sets the request method.

静的 No
パラメータ
パラメータ デフォルト 説明
$method string, required The name of the parameter to be returned. This must be exactly the same as defined in the route.
返り値 current instance
// Set the request method on a forged request
$params = Request::forge('some/route')->set_method('POST');

param($param, $default = null)

Returns a specific named parameter in the route that triggered this request, of the default if the parameter is not found.

静的 No
パラメータ
パラメータ デフォルト 説明
$param string, required The name of the parameter to be returned. This must be exactly the same as defined in the route.
$default
null
value to be returned if the named parameter requested is not defined.
返り値 mixed
// get a specific named parameter called 'name'
$param = Request::active()->param('name', 'none');

The routing section explains how named paramaters can be defined in a route.

parent()

リクエストを生成したリクエスト

静的 No
パラメタ No
返り値 Fuel\Core\Request オブジェクト。メインリクエストの場合はnull。
// 現在実行されているリクエストの親を取得
$parent = Request::active()->parent();

children()

リクエスト処理中に生成されたリクエストの各種オブジェクト。

静的 No
パラメタ No
返り値 Fuel\Core\Request オブジェクトの配列
// メインリクエスト処理中に生成された各種リクエストを取得
$children = Request::main()->children();

main()

main メソッドはメインリクエストのインスタンス (最初のページリクエストで生成されたもの) を返します。

静的 はい
パラメタ No
返り値 Fuel\Core\Request オブジェクト、あるいはメインリクエストインスタンスが存在しない場合は false を返す。
$main = Request::main();

これは最初に実行されたリクエストインスタンスであって、必ずしも現在のリクエストのルート親 (root parent) のインスタンスではありません。 たとえば、メインリクエストが 404 で (_404_ にルート付けられたものが実行された) その後に新しいリクエストを生成するという様なケースがそれにあたるでしょう。

active()

active メソッドはアクティブなリクエストインスタンスを返します。

静的 はい
パラメタ No
返り値 Fuel\Core\Request オブジェクト、 あるいはアクティブなリクエストインスタンスが存在しない場合は false を返す。
$active = Request::active();

add_path($path, $prefix = false)

The add_path method allows you to add a search path to the current request instance. The search paths are used by Finder::search() to locate files within your application.

静的 No
パラメタ
パラメタ 初期値 説明
$path 必須 リクエスト一覧に、ローカルサーチパスを加える
$prefix
false
false なら、パスはサーチパスの後ろに、true ならサーチパスの前に付加されます。
返り値 void
// アプリケーションの myfiles フォルダをアクティブなリクエストインスタンスのサーチパスに付け加える。
Request::active()->add_path(APPPATH.'myfiles'.DS);

get_paths()

get_paths メソッドは設定されているサーチパス一覧を返します。

静的 No
パラメタ No
返り値 void
// アクティブなリクエストインスタンス内で設定されているサーチパスを取得
$paths = Request::active()->get_paths();