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

109 lines
3.2 KiB
XML
Raw Normal View History

2004-04-13 11:47:32 +00:00
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision$ -->
2005-12-05 21:15:38 +00:00
<!-- EN-Revision: 1.8 Maintainer: yannick Status: ready -->
2004-12-26 17:02:12 +00:00
<refentry id="api.register.function">
<refnamediv>
2005-12-05 21:15:38 +00:00
<refname>register_function()</refname>
<refpurpose>D<EFBFBD>clare dynamiquement des plugins de fonction de templates</refpurpose>
2004-12-26 17:02:12 +00:00
</refnamediv>
<refsect1>
2005-12-05 21:15:38 +00:00
<title>Description</title>
2004-12-26 17:02:12 +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>
</methodsynopsis>
<para>
2005-12-05 21:15:38 +00:00
Il faut passer en param<61>tres le nom de la <link linkend="plugins.functions">fonction
de templates</link>, suivi par le nom de la fonction PHP qui l'impl<70>mente.
2004-12-26 17:02:12 +00:00
</para>
<para>
2005-12-05 21:15:38 +00:00
La fonction PHP <parameter>impl</parameter> peut <20>tre soit :
2004-12-26 17:02:12 +00:00
</para>
2005-12-05 21:15:38 +00:00
<orderedlist numeration="loweralpha">
<listitem>
<para>
une cha<68>ne de caract<63>res contenant le nom de la fonction
</para>
</listitem><listitem>
<para>
un tableau de la forme <literal>array(&amp;$object, $method)</literal> o<>
<literal>&amp;$object</literal> est une r<>f<EFBFBD>rence <20> un objet et
<literal>$method</literal> est le nom de la m<>thode
</para>
</listitem><listitem>
<para>
un tableau de la forme <literal>array(&amp;$class, $method)</literal> o<>
<literal>$class</literal> est le nom de la classe et
<literal>$method</literal> est une m<>thode de cette classe.
</para>
</listitem>
</orderedlist>
2004-12-26 17:02:12 +00:00
<para>
2005-12-05 21:15:38 +00:00
Les param<61>tres <parameter>cacheable</parameter> et
2004-12-26 17:02:12 +00:00
<parameter>cache_attrs</parameter> peut <20>tre omis dans la
plupart des cas. Voir <link
linkend="caching.cacheable">Contr<74>ler la mise en cache des sorties des Plugins</link>
pour plus d'informations concernant cette utilisation.
</para>
<example>
2005-12-05 21:15:38 +00:00
<title>Exemple avec register_function()</title>
2004-12-26 17:02:12 +00:00
<programlisting role="php">
<![CDATA[
<?php
2005-12-05 21:15:38 +00:00
$smarty->register_function('date_now', 'print_current_date');
2004-04-13 11:47:32 +00:00
function print_current_date ($params) {
extract($params);
if(empty($format))
$format="%b %e, %Y";
echo strftime($format,time());
}
2004-12-26 17:02:12 +00:00
?>
2005-12-05 21:15:38 +00:00
]]>
</programlisting>
<para>
O<> le template est :
</para>
<programlisting>
<![CDATA[
{date_now}
{* ou, format<61> diff<66>remment *}
{date_now format="%Y/%m/%d"}
2004-12-26 17:02:12 +00:00
]]>
</programlisting>
</example>
2005-12-05 21:15:38 +00:00
<para>
Voir aussi
<link linkend="api.unregister.function">unregister_function()</link> et
les <link linkend="plugins.functions">plugins de fonction</link>.
</para>
2004-12-26 17:02:12 +00:00
</refsect1>
</refentry>
2005-12-05 21:15:38 +00:00
2004-04-13 11:47:32 +00:00
<!-- 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
2005-12-05 21:15:38 +00:00
-->