Module views are defined in the file "module.php". A module view makes it possible to access a PHP file. In our example we define the name of the view list with $ViewList['list'] and forward to the custom "PHP script list.php".
We also want to send some parameters to the view. For example, we define two parameters (ParamOne and ParamTwo) with the statement:
'params' => array('ParamOne','ParamTwo')
... in the script module.php.
<?php // Introduction in the development of eZ Publish extensions $Module = array( 'name' => 'Example Modul1' ); $ViewList = array(); // new View list with 2 fixed parameters and // 2 parameters in order // http://.../modul1/list/ $Params['ParamOne'] / // $Params['ParamTwo']/ param4/$Params['4Param'] /param3/$Params['3Param'] $ViewList['list'] = array( 'script' => 'list.php', 'functions' => array( 'read' ), 'params' => array('ParamOne', 'ParamTwo'), 'unordered_params' => array('param3' => '3Param', 'param4' => '4Param') ); // The entries in the user rights // are used in the View definition, to assign rights to own View functions // in the user roles $FunctionList = array(); $FunctionList['read'] = array(); ?>
Listing 2: View configuration file: extension/jacextension/modules/modul1/module.php
The resulting URL is:
http://localhost/ez/index.php/plain_site/modul1/list/<ValueParamOne>/<ValueParamTwo>
Later we can access the variables in list.php with the following commands:
$valueParamOne = $Params['ParamOne']; $valueParamTwo = $Params['ParamTwo'];
This representation of parameter access is called ordered parameters.
Unordered parameters adjust to the ordered parameters and consist of name-value pairs. For example:
http://localhost/ez/index.php/plain_site/modul1/list/ValueParamOne/ValueParamTwo/(param3)/ValueParam3/(param4)/ValueParam4
The definition is similar to the ordered parameters in "module.php" with:
'unordered_params' => array('param3' => '3Param', 'param4' => '4Param' )
Here we specified that param4 in URL matches 4param parameter in the PHP view.
For example, if the View command has the value .../param4/141, then eZ Publish recognises that the parameter "param4" has been specified and we can read value 141 from the parameter array of the module with the statement:
$Params['4Param']
Unordered parameters can change their order. If no unordered parameter is set, then eZ Publish sets the value to false. Ordered parameters must be defined; otherwise they are assigned a NULL (zero) value.
The URL http://localhost/ez/index.php/plain_site/modul1/list/table/5/(param4)/141/(param3)/131 specifies the parameter view as follows:
$Params['ParamOne'] = 'table'; $Params['ParamTwo'] = '5'; $Params['3Param'] = '131'; $Params['4Param'] = '141';
For more information, refer to the eZ Publish documentation at
http://doc.ez.no/eZ-Publish/Technical-manual/4.x/Concepts-and-basics/Modules-and-views.
The general convention is to create a PHP file with a file name corresponding to the view name in the URL. This allows you to recognise from the URL which PHP file is being loaded. For example:
http://localhost/ez/index.php/plain_site/content/view/full/2
...is forwarding the view.php in the kernel module "content" (<ezroot>/kernel/content/view.php).
Hint: The kernel modules of eZ Publish are a valuable source of information and examples for programmers new to eZ Publish. The structure of kernel modules is the same as for an extension, for example our modul1 example above.
To visualize the call of the view list on the screen, we add the "echo" command in list.php, which interprets the parameters on the screen. The listing below shows our code for list.php:
<?php // take current object of type eZModule $Module = $Params['Module']; // read parameter Ordered View // http://.../modul1/list/ $Params['ParamOne'] / $Params['ParamTwo'] // for example .../modul1/list/view/5 $valueParamOne = $Params['ParamOne']; $valueParamTwo = $Params['ParamTwo']; // read parameter UnOrdered View // http://.../modul1/list/(param4)/$Params['4Param']/(param3)/$Params['3Param'] // for example.../modul1/list/.../.../(param4)/141/(param3)/131 $valueParam3 = $Params['3Param']; $valueParam4 = $Params['4Param']; // show values of the View parameter echo 'Example: modul1/list/'. $valueParamOne .'/ '. $valueParamTwo .'/(param4)/'. $valueParam4 .'/(param3)/'. $valueParam3; ?>
Listing 3. Function file of view list: extension/jacextension/modules/modul1/list.php
Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2013 eZ Systems AS (except where otherwise noted). All rights reserved.