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

87 lines
2.7 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision$ -->
<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>
Si può usare questa funzione per registrare dinamicamente
funzioni plugin per i template. Dovete fornire il nome della
funzione di template, seguito dalla funzione PHP da richiamare
che implementa tale funzione.
</para>
<para>
Il parametro <parameter>impl</parameter>, contenente la funzione
callback, può avere uno dei seguenti valori: (a) una stringa
contenente il nome della funzione (b) un array nella forma
<literal>array(&amp;$oggetto, $metodo)</literal>, dove
<literal>&amp;$oggetto</literal> è il riferimento ad un
oggetto e <literal>$metodo</literal> è una stringa contenente
il nome di un metodo (c) un array nella forma
<literal>array(&amp;$classe, $metodo)</literal> dove
<literal>$classe</literal> è un nome di classe e
<literal>$metodo</literal> è un metodo statico della
classe.
</para>
<para>
<parameter>cacheable</parameter> e <parameter>cache_attrs</parameter>
possono essere omessi nella maggioranza dei casi. Consultate
<link linkend="caching.cacheable">Controllo della Cache per l'output dei Plugins</link>
per capire come usarli.
</para>
<example>
<title>register_function</title>
<programlisting role="php">
<![CDATA[
<?php
$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());
}
}
// ora potete usare questa funzione in Smarty per stampare la data attuale: {date_now}
// oppure {date_now format="%Y/%m/%d"} per formattarla.
?>
]]>
</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
-->