Files
smarty/docs/ru/programmers/api-functions/api-register-function.xml
2008-05-25 15:06:11 +00:00

84 lines
3.2 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="UTF-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 0 Maintainer: freespace Status: ready -->
<refentry id="api.register.function">
<refnamediv>
<refname>register_function</refname>
<refpurpose></refpurpose>
</refnamediv>
<refsect1>
<title />
<methodsynopsis>
<type>void</type><methodname>register_function</methodname>
<methodparam><type>string</type><parameter>name</parameter></methodparam>
<methodparam><type>mixed</type><parameter>impl</parameter></methodparam>
<methodparam choice="opt"><type>bool</type><parameter>cacheable</parameter></methodparam>
<methodparam choice="opt"><type>mixed</type><parameter>cache_attrs</parameter></methodparam>
</methodsynopsis>
<para>
Используется для динамической регистрации плагинов функций шаблона.
Передается наименование функции шаблона и имя функции, реализующей ее.
</para>
<para>
Функция обратного вызова PHP <parameter>impl</parameter> может быть
(a) строка, содержащая имя функции, или (b) массив вида
<literal>array(&amp;$object, $method)</literal>, где
<literal>&amp;$object</literal> является ссылкой на
объект, а <literal>$method</literal> является строкой,
содержащей имя метода, или (c) массив в форме
<literal>array($class, $method)</literal>, где
<literal>$class</literal> является именем класса, а
<literal>$method</literal> является методом этого
класса.
</para>
<para>
<parameter>cacheable</parameter> и <parameter>cache_attrs</parameter>
в большинстве случаев могут быть опущены. Смотрите <link
linkend="caching.cacheable">Управление кэшированием результатов работы плагинов</link>
для получения информации об их правильном использовании.
</para>
<example>
<title>register_function</title>
<programlisting role="php">
<![CDATA[
$smarty->register_function("date_now", "print_current_date");
function print_current_date($params)
{
if(empty($params['format'])) {
$format = "%b %e, %Y";
} else {
$format = $params['format'];
return strftime($format,time());
}
}
// теперь вы можете использовать ее в Smarty чтобы вывести текущую дату: {date_now}
// или {date_now format="%Y/%m/%d"} чтобы задать формат.
?>
]]>
</programlisting>
</example>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->