Fuel Documentation

Request Class

The Request class processes URI requests. It is used by FuelPHP in index.php to process the users URI request, and you need it to generates request 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;

show_404($return = false)

The show_404 method will display or return the applications 404 page. If none is configured in your config routes.php, the FuelPHP 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();

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();