-
-
Notifications
You must be signed in to change notification settings - Fork 2
3. Request
DA edited this page Jun 13, 2019
·
9 revisions
The Request
class provides you with the flexibility to get all the information needed about a request made to your application. The Request
class exists in the context of a successful route. In other words, if the routing is not successful then there is no easy way to have access to the Request
class and to leverage its powerful functionalities.
Learn more about
Routing
here
From the moment a route is successful, the Request
class is available for use.
- It can be accessed from the context of any
Class
created in the/application
folder by invoking a global helper method:
request();
- In the context of a
Controller
, theRequest
is a property of these classes:
use Caligrafy\Controller;
class BookController extends Controller {
public function test()
{
dump($this->request); // will return the entire request object
}
}
public $method; // retrieves the request method
public $uri; // retrieves the URI
public $fullUri; // retrieves the the full URI including the query parameters
public $userAgent; // retrieves the User Agent of the request
public $cookie; // retrieves the Cookie headers
public $currentRoute; // retrieves the current route
public $fetch; // retrieves an array of all the parameters fetched from the request and the URI
public $parameters; // retrieves an object model of all the request parameters
public function fetch($argument); //returns the value of a specific parameter
public function files($HTMLFileName); //returns an array of all the uploaded files through a FORM
public function wantsJson(); //returns true if the request is an API call
public function parameters(); //returns an array of all the request parameters