mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-03 13:51:36 +01:00
83 lines
2.8 KiB
XML
83 lines
2.8 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 1.3 Maintainer: yannick 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>
|
|
Utilisée pour déclarer dynamiquement des plugins de fonction
|
|
de templates. Il faut passer en paramètres le nom de la fonction
|
|
de templates, suivi par le nom de la fonction PHP qui l'implémente.
|
|
</para>
|
|
<para>
|
|
La fonction PHP <parameter>impl</parameter> peut être soit (a) une
|
|
chaîne de caractères contenant le nom de la fonction, soit (b) un tableau
|
|
de la forme <literal>array(&$object, $method)</literal> où
|
|
<literal>&$object</literal> est une référence à un objet et
|
|
<literal>$method</literal> est le nom de la méthode, soit (c) un
|
|
tableau de la forme <literal>array(&$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>
|
|
<para>
|
|
Les paramètres <parameter>cacheable</parameter> et
|
|
<parameter>cache_attrs</parameter> peut être omis dans la
|
|
plupart des cas. Voir <link
|
|
linkend="caching.cacheable">Contrôler la mise en cache des sorties des Plugins</link>
|
|
pour plus d'informations concernant cette utilisation.
|
|
</para>
|
|
<example>
|
|
<title>Exemple avec register_function</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$smarty->register_function("date_now", "print_current_date");
|
|
|
|
function print_current_date ($params) {
|
|
extract($params);
|
|
if(empty($format))
|
|
$format="%b %e, %Y";
|
|
echo strftime($format,time());
|
|
}
|
|
|
|
// vous pouvez maintenant utiliser ceci dans Smarty pour afficher
|
|
// la date actuelle : {date_now} ou {date_now format="%Y/%m/%d"}
|
|
// pour la formater
|
|
?>
|
|
]]>
|
|
</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
|
|
-->
|