Wiki

Custom Fetch

Table of contents:

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'  => ''
                                                              )
                                                      );
?>

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