aliroAbstractRequest
A request object is created early in the processing of every request by Aliro. �The actual object created will belong to either the aliroAdminRequest class or the aliroUserRequest class, according to whether the request is admin side or user side. �For the most part, it does not matter to a developer which it is, since most of the methods are in the comment parent class, aliroAbstractRequest.
There are two ways to get access to the request object. �One is to use the class aliroRequest, which is really just an object factory. �Use this approach by writing aliroRequest::getInstance() to obtain the single instance of the request object. �The other way is simpler. �If you are working inside an application or component that is built using the standard Aliro component manager classes (for example as a result of using the tool provided for creating the outline of a new component) then any of the methods of the request object can be used simply by using $this as the object. �A redirection is automatically carried out to the request object.
The second, simple approach is available in any object that inherits from aliroFriendlyBase, which is the ultimate parent for Aliro component manager classes. �Note that other add-ons do not necessarily inherit from aliroFriendlyBase, and you may need to use aliroRequest to obtain a request object.
The request object will also redirect methods that are implemented in the class aliroCore, most significantly the method getCfg($string) which will return the current value of a configuration item. �You can therefore write something like aliroRequest::getInstance()->getCfg('live_site') or in many contexts $this->getCfg('live_site') to obtain a URI that points to the current site.
Consistent with Aliro standards, none of the request objects has public properties, only public methods. �This provides for greater flexibility in implementation.
Please note that not all public methods in aliroAbstractRequest are part of the API. �Some methods are public simply because they are used by other classes in the Aliro framework and must therefore be declared public. �Only the methods that are described here are intended to be used by add-on software.
Data Handling
getParam ($arr, $name, $def=null, $mask=0) can extract data from an array, and is particularly intended for use with the PHP super globals $_REQEST, $_POST and so on. �The first parameter is the array to be processed which is normally associative. �The second parameter is the key of the desired item, which may or may not be present. �The third parameter is the default, which is used if the key is not found in the array. �If the default is numeric and the given value is not numeric, then the result will be forced to the default value, so getParam provides basic validation of integer items. �The final parameter is optional, and can be one of a set of symbols that modify the processing. �The result will be trimmed unless the mask has _MOS_NOTRIM set. �By default, magic quotes are stripped by getParam, but this action can be suppressed with _MOS_NOSTRIP. �The forcing of non-numeric data given an integer default can be suppressed with _MOS_ALLOWRAW. �When the data item is text, by default any HTML tags will be removed; if _MOS_ALLOWHTML is specified then HTML will be permitted, but it will be validated and corrected. �The validation is strict. �The various symbols can be combined together in the mask by or'ing them together, for example _MOS_NOTRIM | _MOS_NOSTRIP.
doPurify ($string) assumes that the given string is HTML and checks it for strict validity, returning a corrected version of the HTML.
setUserState( $var_name, $var_value ) can be used to save a value of any kind in a way that will persist for as long as the current session. �The first parameter identifies the data, and the second parameter is the data itself. �It can be any PHP data that can be stored in a session.
getUserState( $var_name ) retrieves data stored using setUserState. �Only the name of the data is required.
getUserStateFromRequest($var_name, $req_name, $var_default=null) combines session storage and request data. �The name given as the first parameter is used not only to identify stored data, but also to look in $_REQUEST. �If data is found in $_REQUEST by using the name as a key, then that data is both saved and returned to the caller. �If none is found, then stored data from earlier requests is returned, having been held as session data. �Failing both of those, the default value is returned.
Handling metadata, title and other head section information
The page that is sent back to the browser is constructed after all processing by add-ons to the Aliro framework have completed. �It is therefore possible for any add-on to request that metadata be added to the header.
addScript ($relativeFile, $position='default') will add a link to a file containing Javascript. �The first parameter is a string specifying the relative path to the file; the link in the header will be fully specified. �Possible positions are head, early, default or late. �The first of these requests that the link be placed in the HTML head section. �The others result in the link being placed at the end of the body section. �To some extent, links at the end can be ordered by choosing early, default or late.
addCSS ($relativeFile, $media='screen') will add a link to a file containing CSS. �This type of link is always placed in the head section of the HTML. �The media type can be specified or allowed to default to screen. �Only the relative path to the CSS file is required, and the method turns this into a fully specified link.
addCustomHeadTag ($html, $position='head') can be used to add any kind of code to the head section, or to the bottom of the body section through the use of the position values available for addScript, as described above.
addMetaTag($name, $content, $prepend=, $append=)
appendMetaTag ($name, $content)
prependMetaTag ($name, $content)
setPageTitle ($title=null)�sets the title element within the head section of the HTML.
getPageTitle () returns the current setting for the title element.
General Information
getComponentName () will return the name of the component that is being triggered by the current request. �It is uncertain whether this needs to be part of the API, comments to the project architect please.
getMenu () returns the menu object, of the class aliroMenu, that is thought by Aliro to most closely match the current URI.
getItemid () returns the ID number of the menu entry, if any, that is thought by Aliro to most closely match the current URI. �Aliro does not use an Itemid value in its URIs and if one is coded, it will be ignored, except to the extent that Aliro works by matching the URI to the menu entries. �It is doubtful whether this method is part of the API. �If you think it is needed please advise the project architect.
getTemplate () returns the formal name of the currently active template.
Error Handling
setErrorMessage ($message, $severity=_ALIRO_ERROR_FATAL) will record an error message and its severity, for display to the browser. �The severity should use one of the standard set of symbols provided for errors. �The message can be any string, and should be translated into the current language.
isErrorLevelSet ($severity) is given a severity level, as described above, and returns a boolean to say whether there are any errors set with that severity level.
Form Validation
Aliro provides help with the processing of HTML forms. �This consists of setting an ID and a code in a form, and simultaneously recording the information in session data. �When the form is submitted, it can be checked for validity. �Possible error conditions are that the form does not have the required code, the form is too old, the code does not match what is expected, or the form has already been processed.
makeFormStamp() returns HTML for inclusion in the form. �It consists of two input elements, and should be positioned legally within the form HTML.
getFormCheckError() returns either a message translated to the current language, or a null string if there is no error.
Redirection
There are many situations where the best thing to do is to trigger a new request. �A number of methods support this. �Some of them provide for the caller to give a message and a severity level. �Aliro themes normally provide a position where any messages will be displayed, and the display is styled according to the severity level associated with the message. �Symbols should be used for severity levels, and the possible symbols are included in the Aliro Definitions document.
redirect ($url=, $message=, $severity=_ALIRO_ERROR_INFORM) is the actual redirect method, which causes a request to the given URL. �If none is supplied, the home page will be the destination. �A message can be added, and if it is, a severity level can be provided. �The default for severity is an information message.
goBack ($message=, $severity=) will cause a redirection to the last entry point. �This will be the�URI of the last request, unless modified by other methods. �Message and severity are optionally added.
redirectSame ($message=, $severity=_ALIRO_ERROR_INFORM) will redirect to the same point as the current request. �Message and severity are optionally added.
noRedirectHere() will prevent the current GET request being used for a goBack.
Session methods
In Aliro there is always a session active before any add-on gains control. �This is true whether or not a user is logged in. �If a user logs in, the session ID is regenerated for security reasons, but the session data is preserved. �It is therefore possible, for example, for a visitor to collect items in a shopping cart, then log in to place the order.
getSession() returns the current session object, an instance of either aliroUserSession or aliroAdminSession, both of which are subclasses of the abstract class aliroSession.
getIP() returns the IP address from which the current request was made, so far as it can be determined.
Utility methods
getClassObject($classname) will return an object of the class specified in the parameter, if possible. �The class is autoloaded if necessary. �If the specified class has a "getInstance" method, then it is assumed to be a singleton and the object returned is the result of calling the static getInstance method. �Otherwise the usual "new" construct is used. �If it is impossible to create an object, then null is returned.
spamOptions() returns an associative array where the keys are a standard of set of terms relating to the "spam status" of some data received in a request, and the values are user displayable equivalents, translated into the current language. �The information provided can be used, for instance, to make a list of options for an administrator to review lists of messages and to set or alter the spam status of each one.
getUnique () will return a six digit number that is unique WITHIN THE CURRENT REQUEST. �The number is pseudo random.