Files
smarty/docs/es/programmers/api-functions/api-register-function.xml

110 lines
3.1 KiB
XML
Raw Normal View History

2004-10-07 18:50:52 +00:00
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision$ -->
<refentry id="api.register.function">
<refnamediv>
<refname>register_function()</refname>
<refpurpose>Registra dinamicamente un plugin de funci<63>n para un template</refpurpose>
2004-10-07 18:50:52 +00:00
</refnamediv>
<refsect1>
<title>Descripci<EFBFBD>n</title>
2004-10-07 18:50:52 +00:00
<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>
2004-10-07 18:50:52 +00:00
</methodsynopsis>
<para>
Pase en el template el nombre de la funci<63>n, seguido
2004-10-07 18:50:52 +00:00
por el nombre de la funci<63>n PHP que implementa esto.
</para>
<para>
La llamada a la funcion-php <parameter>impl</parameter> puede ser:
</para>
<orderedlist numeration="loweralpha">
<listitem>
<para>
a una cadena conteniendo el nombre de la funci<63>n o
</para>
</listitem><listitem>
<para>
un arreglo con la forma
<literal>array(&amp;$object, $method)</literal> con
<literal>&amp;$object</literal> siendo una referencia para un objeto y
<literal>$method</literal> siendo una cadena conteniendo el nombre del m<>todo
</para>
</listitem><listitem>
<para>
un arreglo con la forma <literal>array(&amp;$class, $method)</literal>
con <literal>$class</literal> siendo el nombre de una clase y
<literal>$method</literal> siendo un metodo de esa clase.
</para>
</listitem>
</orderedlist>
2004-10-07 18:50:52 +00:00
<para>
<parameter>cacheable</parameter> y <parameter>cache_attrs</parameter> pueden ser omitidos
en la mayoria de los caasos.
Vea <link linkend="caching.cacheable">Controlando modos de Salida Cache de
los Plugins</link> para obtener mayores informes.
2004-10-07 18:50:52 +00:00
</para>
<example>
<title>register_function()</title>
2004-10-07 18:50:52 +00:00
<programlisting role="php">
<![CDATA[
<?php
$smarty->register_function('date_now', 'print_current_date');
2004-10-07 18:50:52 +00:00
function print_current_date($params, &$smarty)
2004-10-07 18:50:52 +00:00
{
if(empty($params['format'])) {
$format = "%b %e, %Y";
} else {
$format = $params['format'];
return strftime($format,time());
}
}
?>
]]>
</programlisting>
<para>
y en el template
</para>
<programlisting>
<![CDATA[
{date_now}
{* or to format differently *}
{date_now format="%Y/%m/%d"}
]]>
</programlisting>
</example>
<para>
Ver tambi<62>n <link linkend="api.unregister.function">unregister_function()</link>
y <link linkend="plugins.functions">Plugin functions</link>.
</para>
2004-10-07 18:50:52 +00:00
</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
-->