System object: zajlib


The zajlib object exposes some global features such as error handling, rerouting, file loading, and others. To use the methods below you will need to invoke them directly from the zajlib object. This is usually available via $this->zajlib->method(). If not, it is the one and only global variable that the Outlast Framework makes available, so (for example in static methods or outside of the framework) zajLib::me()->method() will work just as well.

You can access public properties in a similar way: $this->zajlib->baseurl or zajLib::me()->baseurl will give you the root url of your site.

Many of the public zajlib properties are also available as {{ofw.template_variables}}. See the documentation of built-in template variables for more info.

Properties

Each property is a string where not otherwise specified.

basepath – The root path of the project.
baseurl – The root url of the site. This is automatically determined based on the current request.
basefolder – The project root’s subfolder if there is any. Will be empty if none, will have trailing slash if it is set. This is automatically determined.
fullurl – The full request URL without the query string.
fullrequest – The full request URL including the query string.
requestpath – The request path with trailing slash but without base url and without query string.
host – The host of the current request. This is automatically determined, though keep in mind the malicious end user can modify this!
domain – The top level domain and the current domain. (example: ‘mozajik.org’ for www.mozajik.org)
tld – The top level domain. (example: ‘org’ for www.mozajik.org)
subdomain – The subdomain, excluding www. (example: ‘mail’ for www.mail.mozajik.org or for mail.mozajik.org)
app – The currently requested app with trailing slash. Default for example will be ‘default/’.
mode – The currently requested mode with trailing slash.
htver – The currently active htaccess file version.
https – Set to true if current request is a https secure request. (boolean)
protocol – Set to the current protocol, including the colon. Can be http: or https:.
output_started – Set to true if output to user has begun already. (boolean)
compile_started – Set to true if compile of any template has begun already. (boolean)
mozajik – The version number of the current Outlast Framework system.
model_autoloading – A boolean value which if set to false turns off autoloading of model files. This can be useful when integrating in other systems. (boolean)
zajconf – An array which stores the configuration values set in site/index.php. (array)
variable – Variable is a special property that is used to set/get all variables accessible by the template system. Read more about the template system.


error()

Returns an error message and stops execution of the app. Useful for fatal errors.

$this->zajlib->error($message, $display_to_users = false)

@param string $message The error message to display and/or log.
@param boolean $display_to_users If set to true, the message will also be displayed to users even if not in debug mode (but only the message, no backtrace). Defaults to false with a generic error message displayed. You can use this where communicating information is important and not a security risk.

warning()

Returns a warning message but continues execution.

$this->zajlib->warning($message)

@param string $message The warning message to display and/or log.

deprecated()

Displays a deprecation notice and send it to the log file.

$this->zajlib->deprecated($message)

@param string $message The deprecation message to log.

notice()

Displays a notice in the browser’s console log or (if not in debug mode) will send it to the log file.

$this->zajlib->notice($message)

@param string $message The notice message to log.

ajax()

Send an ajax response to the browser.

$this->zajlib->ajax($message)

@param string $message The textual (or HTML) content to send to the browser.

json()

Send json data to the browser.

$this->zajlib->json($data)

@param string|array|object $data This can be a json-encoded string or any other data (in this latter case it would be converted to json data using json_encode).

redirect()

Redirect the user to relative or absolute URL

$this->zajlib->redirect($url)

@param string $url The specific url to redirect the user to.

reroute()

Reroute processing to another app controller.

$this->zajlib->reroute($request, $optional_parameters = false, $reroute_to_error = true, $call_load_method = true);

@param string $request The request relative to my baseurl.
@param $optional_parameters An array of parameters to be passed. The array is an indexed array where the 0 index is the first parameter, 1 index is the second parameter, and so on.
@param boolean $reroute_to_error When set to true (the default), the function will reroute requests to the proper __error method.
@param boolean $call_load_method If set to true (the default), the __load() magic method will be called.
@return mixed Returns whatever the controller returns.


load->file()

Include a file safely as relative to the base path.

$this->zajlib->load->file($file_path, $fail_with_error_message = true, $include_now = true, $scope = "full");

@param string $file_path The file path relative to the base path.
@param boolean $fail_with_error_message If error, then fail with a fatal error.
@param boolean $include_now If set to true (the default), the file will also be included. On false, only the file path will be returned (and $this->loaded will not be set to true!).
@param string $scope Can be “full” (looks for all variations – default), “specific” (looks for a specific relative path and fails if not found), “project” (looks for anything in the projects folder), “plugin” (looks for anything in the plugins folder), “system” (looks for anything in the system folder)
@return boolean Returns false on error, otherwise returns the path of the file found, relative to to basepath

load->controller()

Loads up a controller file and calls it’s __load() method (by default). You can use this -for example- when you want to include other controller’s __load() methods in a __load() method.

$this->zajlib->load->controller($file_name, $optional_parameters=false, $call_load_method=true, $fail_with_error_message = true);

@param string $file_name The relative file name of the controller to load.
@param array|bool $optional_parameters An array or a single parameter which is passed as the first parameter to __load()
@param boolean $call_load_method If set to true (the default), the __load() magic method will be called
@param boolean $fail_with_error_message If error, then fail with a fatal error.
@return mixed|zajController Returns whatever the __load() method returns. If the __load() method is not invoked, the controller object is returned. A return by __load of explicit false is meant to signify a problem. Or it may also mean that the controller was not loaded (if $fail_with_error_message is false).

load->app()

Apps autoload, so you will usually not need to use this. Use $this->zajlib->reroute() (see above) if you want to send control to another app.

You can also explicitly load libraries using the options below.

$this->zajlib->load->app($request, $optional_parameters=false, $reroute_to_error=true, $call_load_method=true)

@param string $request The application request.
@param array|bool $optional_parameters An array of parameters passed to the request method.
@param boolean $reroute_to_error When set to true (the default), the function will reroute requests to the proper __error method.
@param boolean $call_load_method If set to true (the default), the __load() magic method will be called.
@return bool|mixed Returns whatever the app endpoint returns.

As with any zajlib methods, you can also call it from the static context using zajLib::me()->load->app().

load->library()

Libraries autoload, so you will usually not need to use this. Simply invoke the library method using $this->zajlib->library_name->method() in object context or zajLib::me()->library_name->method() in static context. The library object will be created the first time you call any method.

You can also explicitly load libraries using the options below.

$this->zajlib->load->library($name, $optional_parameters=false, $fail_with_error_message = true)

@param string $name The name of the library to load.
@param array|bool $optional_parameters An array of optional parameters which are stored in {@link zajLibExtension->options}
@param boolean $fail_with_error_message If error, then fail with a fatal error.
@return zajLibExtension|bool Returns a zajlib object or false if fails.

As with any zajlib methods, you can also call it from the static context using zajLib::me()->load->library()

load->model()

Models autoload, so you will typically not need to use this method. Simply invoke the model ModelName::static_method() and it will be loaded for you.

You can turn model autoloading on or off using the model_autoloading property on zajLib:

// Turn off autoloading
$this->zajlib->model_autoloading = false;
// Turn on autoloading
$this->zajlib->model_autoloading = true;

If you want to explicitly load a model you can use the options below.

$this->zajlib->load->model($name, $optional_parameters = false, $fail_with_error_message = true);

@param string $name The name of the model to load.
@param array|boolean $optional_parameters This will be passed to the __load method (not yet implemented)
@param boolean $fail_with_error_message If error, then fail with a fatal error.
@return boolean Will return true if successfully loaded, false if not.

As with any zajlib methods, you can also call it from the static context using zajLib::me()->load->model()

Outlast Web & Mobile Development (c) 2018 | Privacy Policy |