Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Helpers

fballiano edited this page Aug 31, 2012 · 1 revision

Helpers are useful shortcuts to speed up tedious programming operations and they are also precious in adding new functionalities to the core p4a objects.

For example when you call the method useToolbar in your p4a_mask the system searches a p4a_mask_usetoolbar function in the helpers directories.

Example: p4a_mask_usetoolbar.php helper

Building and displaying a toolbar in a mask may be a tedious operation.

$this->build('p4a_standard_toolbar', 'toolbar');
$this->toolbar->setMask($this);
$this->display('top', $this->toolbar);

In a perfect world we can call useToolbar(toolbartype) in a p4a_mask instance and the system will build and display for us the toolbar. The problem is that p4a_mask doesn't have a method useToolbar.

$this->useToolbar('standard');

A helper can solve this problem. The system searches for a p4a_mask_usetoolbar.php file in the helpers directories. The file p4a_mask_usetoolbar.php must have a function called p4a_mask_usetoolbar.

//$obj is the object that calls the method useToolbar (in the example the mask)
//$params it the array of params
function p4a_mask_useToolbar($obj,$params)
{
	$toolbar_type = $params[0];
	$obj->build("p4a_{$toolbar_type}_toolbar",'toolbar');
	$obj->toolbar->setMask($obj);
	$obj->display('top', $obj->toolbar);
}

Explanation

The system helpers are in the p4a/helpers directories. Your helpers must be saved in your libraries application path (yourapplicationpath/libraries). When you call a non existent method the system searches for a {$class_name}_{$method} function. If the function is not found the system searches for {$parent_class_name}_{$method} and behaves in the same way with the complete parents object tree.