Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > by-pkgid > 8377d4bb25a3992aad680df2952f4b71 > files > 27

php-smarty-doc-2.6.26-1mdv2010.0.noarch.rpm

<HTML
><HEAD
><TITLE
>register_function()</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="Smarty Manual"
HREF="index.html"><LINK
REL="UP"
TITLE="Smarty Class Methods()"
HREF="api.functions.html"><LINK
REL="PREVIOUS"
TITLE="register_compiler_function()"
HREF="api.register.compiler.function.html"><LINK
REL="NEXT"
TITLE="register_modifier()"
HREF="api.register.modifier.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=ISO-8859-1"></HEAD
><BODY
CLASS="refentry"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Smarty Manual</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="api.register.compiler.function.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="api.register.modifier.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="api.register.function"
></A
>register_function()</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN6145"
></A
>register_function()&nbsp;--&nbsp;dynamically register template function plugins</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN6148"
></A
><H2
>Description</H2
>void <B
CLASS="methodname"
>register_function</B
> ( string name, mixed impl [, bool cacheable [, mixed cache_attrs]])<BR
></BR
><P
>&#13;   Pass in the <A
HREF="plugins.functions.html"
>template function</A
>
   name,  followed by the PHP  function name that implements it.
  </P
><P
>&#13;   The php-function callback <TT
CLASS="parameter"
><I
>function</I
></TT
> can be either:
   <P
></P
><UL
><LI
><P
>&#13;       A string containing the function <TT
CLASS="parameter"
><I
>name</I
></TT
>
       </P
></LI
><LI
><P
>&#13;       An array of the form <TT
CLASS="literal"
>array(&#38;$object, $method)</TT
> with
       <TT
CLASS="literal"
>&#38;$object</TT
> being a reference to an
       object and <TT
CLASS="literal"
>$method</TT
> being a string
       containing the method-name
       </P
></LI
><LI
><P
>&#13;       An array of the form
       <TT
CLASS="literal"
>array(&#38;$class, $method)</TT
> with
       <TT
CLASS="literal"
>$class</TT
> being the class name and
       <TT
CLASS="literal"
>$method</TT
> being a method of the class.
       </P
></LI
></UL
>
  </P
><P
>&#13;   <TT
CLASS="parameter"
><I
>cacheable</I
></TT
> and <TT
CLASS="parameter"
><I
>cache_attrs</I
></TT
> can be
   omitted in most cases. See <A
HREF="caching.cacheable.html"
>controlling cacheability of plugins output</A
>
   on how to use them properly.
  </P
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN6187"
></A
><P
><B
>Example 13-1. register_function()</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$smarty</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">register_function</span><span style="color: #007700">(</span><span style="color: #DD0000">'date_now'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'print_current_date'</span><span style="color: #007700">);<br /><br />function&nbsp;</span><span style="color: #0000BB">print_current_date</span><span style="color: #007700">(</span><span style="color: #0000BB">$params</span><span style="color: #007700">,&nbsp;&amp;</span><span style="color: #0000BB">$smarty</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;if(empty(</span><span style="color: #0000BB">$params</span><span style="color: #007700">[</span><span style="color: #DD0000">'format'</span><span style="color: #007700">]))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$format&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"%b&nbsp;%e,&nbsp;%Y"</span><span style="color: #007700">;<br />&nbsp;&nbsp;}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$format&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$params</span><span style="color: #007700">[</span><span style="color: #DD0000">'format'</span><span style="color: #007700">];<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #0000BB">$format</span><span style="color: #007700">,</span><span style="color: #0000BB">time</span><span style="color: #007700">());<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></TD
></TR
></TABLE
><P
>&#13;   And in the template
   </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="programlisting"
>{date_now}

{* or to format differently *}
{date_now format="%Y/%m/%d"}</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
><P
>&#13;See also
<A
HREF="api.unregister.function.html"
><TT
CLASS="varname"
>unregister_function()</TT
></A
>
and the
<A
HREF="plugins.functions.html"
>plugin functions</A
> section.
</P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="api.register.compiler.function.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="api.register.modifier.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>register_compiler_function()</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="api.functions.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>register_modifier()</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>