ApexThe
|
Method | Description |
---|---|
_config() | Get a single configuration variable (eg. core:domain_name, transaction:base_currency, etc.) |
has_config() | Returns a boolean whether or not the configuration variable exists. |
getall_config() | Returns an array consisting of all configuration variables. |
Apex Request
There are various methods available to obtain and set information regarding the request that is specific to Apex, and are explained in the below table.
Method | Description |
---|---|
get_action() | Returns the value of any "submit" form field previously posted, blank otherwise. |
get_uri() / set_uri($uri) | Gets or sets the URI that is being accessed, and is used to determine which .tpl template file from within the /views/ directory is displayed. |
get_userid() / set_userid($userid) | Gets or sets the ID# of the authenticated user. Generally, you should never have to set the userid as the authentication engine does that automatically, but useful to obtain the ID# of the user. |
get_area() / set_area($area) | Gets or sets the current active area. Generally, this will always be either "admin", "members" or "public", is automatically determined based on URI, and should never have to be set. |
get_theme() / set_theme($theme) | Gets or sets the theme being displayed. Generally, you will never need either of these, as they are used by the template engine only. |
get_http_controller() | Gets the HTTP controller that will be handling the request, resides in the /src/core/service/http_requests/ directory. |
Examples
namespace apex;
use apex\app;
// Submit button from previous form was "create"
if (app::get_action() == 'create') {
// Display the /public/winner template instead if first 500 members.
if (app::get_userid() <= 500) {
app::set_uri('winner');
}
}
HTTP Request
The below methods allow you to retrive various information about the HTTP request itself. Please note, this information is read-only and can not be set.
Method | Description |
---|---|
get_ip() | IP address of the client connecting. |
get_user_agent() | The user agent of the client connecting. |
get_host() | The hostname being connected to (ie. your domain name) |
get_port() | The port being connected to, generally either 80 or 443 (SSL). |
get_protocol() | The HTTP protocol version being used, generally 1.1. |
get_method() | The request method of the request (ie. GET, POST, DELETE, etc.) |
get_content_type() | The content type passed by the client. |
get_uri_segments() | An array of the URI split by the / character, with the first segment being left off in case it's an HTTP controller (eg. admin, members, repo, etc.) |
get_request_body() | Get the full raw contents of the request body. Useful if example, a chunk of JSON was POSTed to the software. |
_header($name) | Array of all instances of the $name within the HTTP header sent by the client. |
_header_line($name) | A single comma delimited line of all instances of the $name HTTP header passed by the client. |
HTTP Response
The below methods allow you to control the response that is given back to the client.
Method | Description |
---|---|
set_res_http_status($code) | Set the HTTP status code of the response (eg. 404, 500, 403, etc.. Defaults to 200 OK. |
set_res_content_type($type) | Set the content type of the HTTP response. Defaults to "text/html". |
set_res_header($name, $value) | Set a custom HTTP header within the response. |
set_res_body($contents) | Set the actual contents of the response. |
echo_response() | Outputs the response including HTTP status and headers to the browser. |
Additional
There's various additional methods available that will be useful at times, and are explaind in the below table.
Method | Description |
---|---|
get_instance() | Returns the singular instance of the app class. Never really needed. |
update_config_var($var, $value) | Updates a configuration variable. |
get_counter($name) | Increments the specified counter by 1, and returns the new integer. Useful when you need incrementing numbers outside of the database. |
get_timezone() | Returns the timezone of the current session. |
get_language() | Returns the language of the current session. |
get_currency() | Returns the base currency of the current session. |
Dependency Injection
The app class also acts as the container for dependency injection. This is explained in more detail elsewhere in the documentation, but the methods available are explained below.
method | Description |
---|---|
get($key) | Get the value of the key from the container. |
has($key) | Returns a boolean as to whether or not the container contains the specified key. |
set($key, $value) | Set a new value within the container. |
make($class_name, array $params = []) | Creates and returns an instance of the specified class. This instance is not saved within the container, and is only created with dependency injection, then returned. |
call([$class_name, $method], array $params = []) | Call a specific method within a class while performing dependency injection directly on the method. This does not save anything within the container, and only calls the method, but does allow for method / setter injection. |
Need a Professional?
Need development work by the creator of Apex? E-mail matt.dizak@gmail.com for a free consultation.
Recent News
Mailing List
Subscribe to the low traffic mailing list to stay updated on Apex.
