Building Aliro Modules
A module is a piece of code that generates a box for placement on the browser screen. The exact placement is chosen by the site administrator, using the capabilities of the current template. Modules do not handle user input, which is always fed to a component. However, they can instigate user actions by providing suitable links.
Module code may be used more than once, generating different boxes. The differences usually stem from a different choice of parameters by the site administrator. A module can specify what parameters it will accept through the packaging XML. Aliro passes the appropriate set of parameters when it calls module code, in the form of an instance of the class aliroParameters. Modules are processed after component processing is completed. Nothing is written to the browser until after module processing is completed, so it is possible for a module to use methods on aliroRequest to add CSS or Javascript that will be appropriately placed in the final browser output.
With Aliro, a module can be built as an independent entity. In this case, it will have its own packaging XML, which will start off something like:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE extinstall SYSTEM "http://www.aliro.org/xml/extinstall.dtd">
<extinstall type="module" userclass="mod_simplemenu" version="2.0">
The main XML element must specify a userclass attribute, which determines what class will be invoked when the module is needed. Optionally, a method can be specified by putting a comma followed by the method name immediately after the class name in the userclass attribute. If no method is specified, Aliro will use the default method name of "activate".
Another way to build a module is as part of an application. This is similar to a component, but can have modules and/or plugins integrated with it. In this case, the module details will be specified within the packaging XML for the application. For example, the login application includes a module for showing line with login, profile and registration links, and the relevant part of the XML is:
<module userclass="loginServices,loginStrip">
<name>Minimal Login Strip Module</name>
<formalname>mod_login_strip</formalname>
<description>Provides a simple login strip with links to actions</description>
</module>
In this case, the method is specified as "loginStrip" as well as the class being stated to be "loginServices". Considerable flexibility is available on how to build applications with this ability to specify the class and method that implements a module. Remember also that provided the packaging XML correctly identifies them, Aliro manages all the code loading required so that the class will be automatically loaded when needed.
The module method that receives control from Aliro should have a declaration compatible with:
public function activate ($module, &$content, $area, $params) {
although any of the names can be changed. Note that it is critically important that the second parameter be passed by name (or reference) and not by value. It is a general Aliro policy to build output to the browser within the system and only send it to the browser when it is largely complete. This is essential if all code (including add-ons) is to be able to carry out a full range of operations, including setting values in the <head> section, setting cookies and so on. The output to the browser from the module is therefore placed in the second parameter, and used by Aliro in the building of the browser page.
The first parameter is an instance of the class aliroModule and contains details of the module being called. The third parameter is an instance of aliroScreenArea and provides information about the block within the template in which the box created by the module will appear. Finally, the fourth parameter is an instance of aliroParameters that can be immediately used by the module to obtain parameter values set for this particular use of the module to create a screen box. The actual parameters available from the parameter object depend on the packaging XML for the module.
There are no comments on this page. [Add comment]