Request Class
The Request class processes URI requests. It is used by Fuel in index.php to process the users URI request, and you need it to generate requests in an HMVC context.
factory($uri = null, $route = true)
The factory method returns a new request object.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$uri |
null
|
The URI being requested. If this parameter is not present, the URI class will be used to detect the URI. |
$route |
true
|
If true, the URI passed or detected will be processed by the routing class. If no route is present, a 404 will be generated. If you request a non-public URI, set this to false. |
|
Returns |
Fuel\Core\Request Object |
Example |
// create the request object for the admin controller, login method
$request = Request::factory('admin/login');
// note that this only creates the object, it does not execute the request!
|
execute()
The execute method executes a request, and stores the resulting response in the request object to be used later.
Static |
No |
Parameters |
No |
Returns |
Fuel\Core\Request Object |
Example |
// create and execute the request object for the admin controller, login method
$request = Request::factory('admin/login')->execute();
|
response()
The response method fetches the response object of the executed request.
Static |
No |
Parameters |
No |
Returns |
Fuel\Core\Response Object |
Example |
// execute the request, fetch the response, and display it
$response = Request::factory('admin/login')->execute()->response();
echo $response;
// The Request object contains a __toString() method as an alternative way to fetch the output
$output = Request::factory('admin/login')->execute();
echo $output;
|
parent()
The Request that created this Request.
Static |
No |
Parameters |
No |
Returns |
Fuel\Core\Request Object or null when it's the main request |
Example |
// get the parent of the current active Request
$parent = Request::active()->parent();
|
children()
The Request objects that were created during this Request.
Static |
No |
Parameters |
No |
Returns |
Array of Fuel\Core\Request Objects |
Example |
// get the Requests that were created during the main Request
$children = Request::main()->children();
|
show_404($return = false)
The show_404 method will display or return the application's 404 page. If none is configured in your config routes.php, the Fuel default 404 page will be used instead. If the configured 404 route is incorrect, an error will be thrown.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$return |
false
|
If false, the result will be echoed out. If true, it will be returned. |
|
Returns |
If $return is false, the method will exit. If not, it will return the html of the 404 page configured. |
Example |
Request::show_404();
|
main()
The main method returns the main Request instance (the one created by the initial
page request).
Static |
Yes |
Parameters |
No |
Returns |
Fuel\Core\Request Object, or false if no main request instance exists. |
Example |
$main = Request::main();
|
This is the first executed Request instance, not necessarily the root parent of the
current Request. That might be the case for example if the main Request 404s and you create a new
Request after that (which is what happens in the _404_ route).
active()
The active method returns the currently active Request instance.
Static |
Yes |
Parameters |
No |
Returns |
Fuel\Core\Request Object, or false if no active request instance exists. |
Example |
$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 Fuel::find_file() to locate files within your application.
Static |
No |
Parameters |
Param |
Default |
Description |
$path |
required |
Path to be added to the list of Request local search paths |
$prefix |
false
|
If false, the path will be appended to the search path. If true, it will be prepended. |
|
Returns |
void |
Example |
// add the applications myfiles folder to the search path of the active request instance
Request::active()->add_path(APPPATH.'myfiles'.DS);
|
get_paths()
The get_paths method returns the defined list of search paths.
Static |
No |
Parameters |
No |
Returns |
void |
Example |
// get the defined search paths of the active request instance
$paths = Request::active()->get_paths();
|