Добро пожаловать на форум PHP программистов!
За последние 24 часа нас посетили 16956 программистов и 1772 робота. Сейчас ищут 1405 программистов ...

setCallbackFunction()

Вернуться к: HTML_Template_Sigma

setCallbackFunction()

setCallbackFunction() – Sets a callback function.

Synopsis

require_once 'HTML/Template/Sigma.php';

mixed HTML_Template_Sigma::setCallbackFunction ( string $tplFunction , mixed $callback , bool $preserveArgs = false )

Sets a callback function. Sigma templates can contain simple function calls. This means that the author of the template can add a special placeholder to it: func_h1("embedded in h1") Sigma will parse the template for these placeholders and will allow you to define a callback function for them. Callback will be called automatically when the block containing such function call is parse()'d.

Please note that arguments to these template functions can contain variable placeholders: func_translate('Hello, {username}'), but not blocks or other function calls.

This should NOT be used to add logic (except some presentation one) to the template. If you use a lot of such callbacks and implement business logic through them, then you're reinventing the wheel. Consider using XML/XSLT, native PHP or some other template engine.

Script:

<?php
function h_one($arg)
{
    return 
'<h1>' $arg '</h1>';
}
// ...
$tpl = new HTML_Template_Sigma(' ... ');
// ...
$tpl->setCallbackFunction('h1''h_one');
// ...
$tpl->show()
?>

template:

... func_h1('H1 Headline') ...

Parameter

string $tplFunction

Function name in the template

mixed $callback

A callback: anything that can be passed to call_user_func_array()

boolean $preserveArgs

If TRUE, then no variable substitution in arguments will take place before function call

Return value

return SIGMA_OK on success, error object on failure

Throws

Possible PEAR_Error values
Error code Error message Reason Solution
SIGMA_INVALID_CALLBACK Callback does not exist The $callback is not an existing function or method Check spelling, check whether the object was correctly instantiated if using the method callback

Note

This function can not be called statically.



Вернуться к: HTML_Template_Sigma

© 2024 «PHP.RU — Сообщество PHP-Программистов»
Главная | Форум | Реклама на сайте | Контакты VIP Сувениры
Разработка компании ODware