Get Smarty

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Check reviews of PHP Web Hosting, compatible with Smarty Templates

Name

register_function

void register_function(string name,
                       mixed impl,
                       bool cacheable,
                       mixed cache_attrs);

Wird verwendet, um Template-Funktion-Plugins dynamisch zu registrieren. Übergeben Sie dazu den Namen der Template-Funktion und den Namen der PHP-Funktion, die die entsprechende Funktionalität bereitstellt.

Der Parameter impl kann als (a) einen Funktionnamen oder (b) einem Array der Form array(&$object, $method), wobei &$object eine Referenz zu einem Objekt und $method der Name der Methode die aufgerufen werden soll ist, oder als Array der Form array(&$class, $method), wobei $class der Name der Klasse und $method der Name der Methode ist die aufgerufen werden soll, übergeben werden.

$cacheable und $cache_attrs können in den meisten Fällen weggelassen werden. Konsultieren Sie Die Ausgabe von cachebaren Plugins Kontrollieren für weitere Informationen.

Example 13.22. register_function (Funktion registrieren)


<?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());
  }
}

// Von nun an k&ouml;nnen Sie {date_now} verwenden, um das aktuelle Datum auszugeben.
// Oder {date_now format="%Y/%m/%d"}, wenn Sie es formatieren wollen.</programlisting>
?>


Comments
No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 1 plus 9? (Are you human?)

Sponsors [info]

Cheap Website Hosting @hostdone.com
email marketing @ActiveCampaign
broadband deals @BroadbandGenie
Best UK Web Hosting @webhost.uk.net
Reliable UK and US Web Hosting @rshosting.com
Cheap US and UK Web Hosting @infrenion.com
I.T Certification Exams @pass-guaranteed.com
Certification Practice Tests @firsttrycertify.com
Certification Practice Exam Questions @ace-it-certifications.com
Broadband Speed Test @broadbandspeed.co.uk
bulk email software @americaint.com
ASP.NET hosting @aspnethosting.co.uk