Incoming Requests
Incoming requests can be of several types, the main ones being GET and POST.
To determine the type of request in a module/add-on, the following methods can be called:
if ($this->isGET()) {
// GET request
}
if ($this->isPOST()) {
// POST request
}
if ($this->isAJAX()) {
// AJAX request
}
Outside the context of modules, the general Request
class is also available:
Request::isGET();
Request::isPOST();
Request::isAJAX();
Request Context
A request can be in different contexts: Frontend, Admin Panel, Cron Task
The following methods are used to determine the context:
if (bff::cron()) {
// The request is executed within a background task started by the cron manager
}
if (bff::adminPanel()) {
// The request is executed within the Admin Panel
}
There are also other helper methods available for obtaining request data:
# Request IP address
$ip = Request::remoteAddress();
# Request HOST
$host = Request::host();
# Request URL
$url = Request::url();
# Request URL with parameters (?test=1)
$url2 = Request::url(true);
# HTTP_REFERER header of the request
$referer = Request::referer();
# HTTP_USER_AGENT header of the request
$agent = Request::userAgent();
# Request protocol (http/https)
$scheme = Request::scheme();
# HTTPS request
$https = Request::isHTTPS();
# Request method: GET, POST, PUT, DELETE, ...
$method = Request::method();