To use the class ModeliXe, it must be included in your php script.
If you use ModeliXe frequently, modify the directive auto_prepend_file of your PHP.ini so as to include it automatically in all of your scripts.
After that it is used in the classic way:
- Including the files ModeliXe, Mxconf and ErrorManager in your script.
- The configuration file.
- Instantiation of the class.
- Instantiation methods.
- Possible declaration of " plug-ins ".
- Parsing of the templates (call of the method SetModeliXe ()).
- Declaration of ModeliXe elements.
- Call the of the class exit method.
Include files ModeliXe, Mxconf and ErrorManager in your scripts
To be able to use ModeliXe you must call it in the header of your files. You do this by including the file ModeliXe.php.
ModeliXe will then include its own dependencies, configuration file Mxconf.php and error manager class ErrorManager.php.
The method that allows you to locate these files according to your own requirements was updated following the beta release of version 7.0 ( 0.7.0 ).
If files Mxconf and ErrorManager aren't situated in the same directory as ModeliXe, you must specify two constants, MX_GENERAL_PATH and MX_ERROR_PATH, before the include of ModeliXe itself. These two constants will contain the path (relative or absolute) of the files Mxconf and ErrorManager.
Note that if you specify relative paths, they must be specified in relation to the path of your file, that includes ModeliXe, and not in relation to the file ModeliXe.php.
Here is an example for a file system tree of the type:
web/project/project1/monfichier.php
web/project/lib/ModeliXe.php
web/project/lib/ErrorManager.php
web/config/project1/Mxconf.php
This would require the following include statements
define('MX_GENERAL_PATH', '../../config/project1');
define('MX_ERROR_PATH', '../lib/');
include('../lib/ModeliXe.php');
The configuration file
After beta version 4.0, ModeliXe integrated a configuration file which had to be named Mxconf.php (since beta version 6.1, the name changed from ModeliXe.conf to Mxconf.php).
In versions after 6.5 ( 0.6.5 ), the configuration was further modified due to the externalization of error management in ErrorManager.
In versions after 7.0 ( 0.7.0 ), the configuration file integrated an new value MX_OUTPUT_TYPE which allows the specification of the general tag type generated on exit by ModeliXe.
15 constants are declared in this file. They permit the modification of the default behaviour of ModeliXe and its error handling.
These constants are as follows:
- MX_FLAGS_TYPE, takes the value " xml ", " classical " or " pear ". It specifies the type of tag syntax used. At the moment " classical " and " pear " are equivalent. If this
constant isn't assigned, the tag syntax used by default is " xml ".
- MX_OUTPUT_TYPE, takes the value "xhtml", "xml" or "html". It specifies the type of tag generated on exit by ModeliXe. If this constant isn't assigned, the tag syntax used by default is " xhtml ".
- MX_TEMPLATE_PATH, defines the directory in which the templates will be situated. It's possible to specify a path in the template declaration, but if this constant is assigned,
the template declaration path will be relative to the MX_TEMPLATE_PATH directory.
- MX_DEFAULT_PARAMETER, definition of the path to the default configuration file, common for the whole site. If you specify a special parameter setting file during the instantiation
of the class, it will override this default.
- MX_CACHE_PATH, specifies a directory to store cached pages.
- MX_CACHE_DELAY, sets a maximum time to live for pages in cache.
- MX_SIGNATURE, activates ("on") or deactivates ("off") ModeliXe signature writing within the generated HTML file. This allows an easier debugging when you are integrating foreign blocks or managing the cache. I suggest you set it to " off " when you move into production, it will save a little time on the server.
- MX_COMPRESS, activates the compression of pages if the browser supports it (on or off).
- MX_REWRITE_URL, uses mode_rewrite to create urls (on or off).
- MX_PERFORMANCE_TRACER, activates performance timing (on or off).
- ERROR_MANAGER_SYSTEM, if set to "on", errors are raised, errors are ignored if set to "off".
- ERROR_MANAGER_LEVEL, defines the tolerated error level, the lower it's set, the less errors are tolerated.
- ERROR_MANAGER_ESCAPE, allows you to specify a substitute local url to use in case of errors.
- ERROR_MANAGER_LOG, allows you to define a log file.
- ERROR_MANAGER_ALARME, specifies a comma separated series of email addresses to which alerts will be will be sent.
Instantiation
$page = new ModeliXe(string $templateFile, [string $sessionParameter], [string $parameterFile], [integer $cacheDelay]);
New! Since ModeliXe version 0.7.0, the parameter setting described in the following paragraph can advantageously be replaced by the ModeliXe's instantiation methods.
During the instantiation of the class, you can specify a series of key-value pairs (such as a session identifier) in the form of a querystring, which will automatically be integrated during the creation of hidden tags and links.
The series is optional and is composed like a querystring as it would appear on an url, for example as this
sid=edfrg45ASlkkO&lang=fr
There's a ModeliXe method which allows you to easily generate a querystring, you can find it here.
During the instantiation of the class, you can specify a file of template parameters as the third argument.
This file allows the customisation of an HTML page during an initial global parsing of the template. This option allows you to adapt a generic template to a particular visual style, without having to manage this modification in the code.
This transformation is automatic and affects the whole template without respect for block division. The syntax of this file will be shown later in this document.
Finally, it's possible to specify a cache duration for the page being generated which differs from default cache duration parameter, by assigning the argument cacheDelay. This argument must be integer and represents a cache duration in seconds. You'll
find fuller information about the use and management of the ModeliXe cache here.
Instantiation Methods
Since ModeliXe version 0.7.0 (beta 7.0), you can use a set of methods to dynamically modify the configuration of ModeliXe.
These methods are divided into two groups, those whose effect can be realized at any time during the use of the class, and those which must be called before the class instancisation by SetModelixe().
Here is the list of the methods of the first group, the call anytime group:
- $page -> SetMxCompress(boolean); activates (on) or deactives (off) compression in the outgoing HTML stream.
- $page -> SetMxModRewrite(boolean); activates (on) or deactivates (off) rewriting of urls by mod_rewrite.
- $page -> SetMxSignature(boolean); activates (on) or deactivates (off) the ModeliXe signature in the generated HTML file, useful for debugging blocks.
- $page -> SetMxSession(string); specifies session parameters which will not be parsed during the use of the cache.
- $page -> SetMxFileParameter(filePath); specifies a (pre-parsing) parameter file for the current page.
Here is the list of the methods of the second group, the call before SetModelixe() group:
- $page -> SetMxTemplatePath(directoryPath); specification of the template directory for the current page.
- $page -> SetMxFlagsType(string); Specification of the template tag syntax to be used (xml or classic/PEAR).
- $page -> SetMxOutputType(string); specification of the tag type generated by ModeliXe (xhtml or html).
- $page -> SetMxCachePath(directoryPath); Specification of the cache directory for the current page.
- $page -> SetMxCacheDelay(integer); Specifies the time in cache value for the current page.
The return value of these methods is the value which they've modified (or not modified). They can also work as get-methods.
Declaration of "plug-ins"
$page -> AddMxPlugin(string $name, string $type, string $fonction);
This feature allows you to declare particular tags associated with external managers.
This allows the flexible reuse of ModeliXe and supports additional dynamic tags in your pages managed by separate , reusable modules.
This feature has been available since version beta 4.0.
It was temporarily discontinued in the beta 6.5, and restored in the beta 6.7 reimplemented to be more performant.
Parsing of the template
$page -> SetModeliXe();
The invocation of this method is compulsory and has to be made after the declaration of "plug-ins" and before all the other call to instance methods the class ModeliXe.
It initiates the analysis of the template, its segmentation, and the address generation of the various blocks which constitutes it, and the list of tags and attributes with in it.
It's this step that allows the addition of new tags under the management of "plug-ins".
Declaration all ModeliXe elements
$page -> MxText(string $path, string $value);
$page -> MxImage(string $path, string $imageFile, [string $title], [string $imageAttribut], [string $getSize]);
$page -> MxUrl(string $path, string $url, string $queryString);
$page -> MxAttribut(string $path, string $value);
$page -> MxFormField(string $path, string $fieldName, string $value, [string $attribut]);
$page -> MxCheckerField(string $path, string $type, string $name, string $value, [string $checked], [string $attribut]);
$page -> MxSelect(string $path, string $name, string | array $selectedValue, array $Value, [string $defaultValue], [int $multipleSize], [string $javascriptAttribut]);
$page -> MxHidden(string $path, queryString $value);
$page -> MxBloc(string $path, string $operator, [string $option]);
This is the collection of methods and dynamic element declarations what we are going to look at in the following chapter.
All the methods have for their first argument a variable titled "path", which uniquely addresses a ModeliXe element in the document tree. The origin of the path is the name of the template file.
We'll get into the details shortly.
Final method
$page -> MxWrite([string $out]);
It accepts an optional argument $out, if one is supplied MxWrite doesn't write page generated to client, but returns the contents of the page, to generate files, for example.
This method allows you to display the finale state of the page which you built with ModeliXe.
|