eZpedia : The Free eZ Publish CMS Documentation Encyclopedia

Custom Fetch

Table of contents:

This is a Stub article. Help the eZ Publish community by expanding it!

Brief

The purpose of a custom fetch is to have an organized way to retrive data from a given data source. You mainly call a custom fetch function from templates. The eZ Publish framework already provide a lot of different fetch functions out-of-the-box. You can create your own custom fetch functions from within your own custom module extension.

Example

The following example is based on the example given by Bruce Morrison on the ez.no forums.

File: extension/ourcustom/modules/ourcustom/function_definition.php

<?php
 
$FunctionList = array();
$FunctionList['CustomFetch'] = array( 'name' => 'customfetch',
                                                  'operation_types' => array( 'read' ),
                                                  'call_method' => array( 'include_file' => 'extension/ourcustom/modules/ourcustom/ourcustomfunctioncollection.php',
                                                  'class' => 'OurCustomFunctionCollection',
                                                  'method' => 'fetchCustomFetch' ),
                                                  'parameter_type' => 'standard',
                                                  'parameters' => array(
                                                    array( 'name'     => 'the',
                                                               'type'     => 'integer',
                                                                'required' => true,
                                                                'default'  => 1
                                                      ),
                                                      array( 'name'     => 'params',
                                                                 'type'     => 'string',
                                                                 'required' => true,
                                                                 'default'  => ''
                                                              )
                                                      );
?>

Please note that the values associated with the keys 'name', 'operation_types' and 'parameter_type' are not used anywhere by eZ Publish itself.

Since eZ Publish 4, the 'include_file' key of the 'call_method' array is deprecated and won't be used anymore. Instead, the module system relies on the PHP 5 autoload feature.

File: extension/ourcustom/modules/ourcustom/ourcustomfunctioncollection.php

<?php
 
class OurCustomFunctionCollection
{
 function OurCustomFunctionCollection()
 {
 }
 function &fetchCustomFetch( $some, $params )
 {
   $result =& retrieve data here
   return array( 'result' => $result );
 }
}
 
?>

File: extension/ourcustom/settings/module.ini.append.php

<?php /* #?ini charset="utf-8"?
 
[ModuleSettings]
ExtensionRepositories[]=ourcustom
ModuleList[]=ourcustom
 
 
*/ ?>

Usage

{def $collection=fetch( ourcustom, customfetch, hash( the, params ) )}

External References

Article provided by eZpedia

All text is available under the terms of the GNU Free Documentation License

Powered by eZ Publish 4.4.0

Hosted by Swiss eZ Publish partner YMC