The template class is a class which all
templates' main classes extend. This class itself is fairly empty,
consisting mostly of basic methods and variables just to satisfy the
interface's requirements. It does, however, include the standard
implementation of the url method. This is
what is called when using the shortcut function
pines_url (unless the current template
implements it).
The url method accepts up to four
arguments, in this order:
$component
The name of the component that the URL should request.
$action
The name of the action that the URL should request.
$params
An associative array of parameters to place in the URL's query string.
$full_location
Whether to use the full location, instead of the relative location. For links in email, RSS feeds, and similar contexts, a full location should be used.
If url is called with no arguments,
it will return the relative URL of the index page.
For more information on templates, see the Template Service section and Templates in Part II.
The module class is used to generate
content using a view and place it into a page. Modules allow Pines
to pass data from the logic portion of a component to the
presentation portion. This allows the business logic to remain the
same no matter which type of page is being constructed (XHTML, RSS,
etc.). Modules select the proper view based on the format provided
by the current template.
Modules have several variables. However, the position and
order variables must be set by using the
attach method or the
constructor.
muid
A unique ID available to views to allow the use of IDs
in HTML. Generated with mt_rand.
title
The module's title. This is usually set by the view.
note
The module's note. This is usually set by the view.
classes
An array of additional classes to be added to the module. This applies only to HTML modules.
content
The modules content. This is almost always, but not necessarily, filled by the output of a view.
component
The component which contains the view.
view
The view from which the content will be retrieved.
position
The position on the page in which the module is placed.
order
The order in which the module is placed in the position.
show_title
Whether or not the title and note of the module should be displayed.
When creating a module, the component, view, position, and order can be specified in the constructor. Position and order are optional. The order is not guaranteed and will be ignored if it is already taken.
// Add the widget form from com_example to the content part of the page.
// Place in order as #2, so #0, and #1 come before it.
$module = new module('com_example', 'widget/form', 'content', 2);
You can also manually attach a module once it is created.
$module = new module('com_example', 'widget/form');
if (isset($position))
$module->attach($position);
else
$module->attach('content');
You can use the module to generate content without putting it into the page.
$module = new module('com_example', 'widget/email');
$email_body = $module->render();
![]() | Caution |
|---|---|
|
Even though the module is not added to the page in this example, it still uses the template's format to find the view. |
Pines provides a blank view (component is "system" and view is "null"), which you can use if you want to add content to the module manually.
// Of course, this example message would be much more suited to use pines_notice() or pines_error(),
// but this is merely an example of what you could do.
$module = new module('system', 'null', 'content');
$module->title = 'Result';
$module->content('The process '.($success ? 'finished successfully.' : 'encountered an error.'));
// And we can retrieve the content to log it.
pines_log($module->get_content());
For more information about creating and using views, see the Views section.