Smarty Registration function, please instruct

Source: Internet
Author: User
Tags echo date
Ask Smarty registration function problem.

$smarty->register_function (' Dateline ', ' handle_dateline '); This is the registration function, what does the first parameter mean?

function Handle_dateline ($params, & $smarty) {}//This is the registered functions, what do these 2 parameters mean?

Does registering a function cause a function to execute? Is it similar to calling a function?


Reply to discussion (solution)

$smarty->register_function (' Dateline ', ' handle_dateline ');
Dateline is the name used in the template.
Such as
{Dateline time= "$time" format= "y-m-d"}
Instead of
{handle_dateline time= "$time" format= "y-m-d"}
Oh, to find their own sins by

function Handle_dateline ($params, & $smarty) {}
$params An array of arguments passed in, such as two elements in the previous example
function body you might write this.
Extract ($params);
echo Date ($format, $time);

$smarty the Smarty object itself, because you might need to access $smarty properties and methods within the function body

$smarty->register_function (' Dateline ', ' handle_dateline ');
Dateline is the name used in the template.
Such as
{Dateline time= "$time" format= "y-m-d"}


Hello, so to speak,
$smarty->register_function (' Dateline ', ' handle_dateline ');
does not pass any parameters to function Handle_dateline ($params, & $smarty) {}??
The statement above the registration function will not cause the function handle_dateline ($params, & $smarty) {} "to execute?"

Does not execute, it just registers a function that needs to be executed when you call it in the template, and the parameters are passed at this time.

Does not execute, it just registers a function that needs to be executed when you call it in the template, and the parameters are passed at this time.


Parameters are passed at the time of invocation, that is, unrelated to the registration function. What's the use of the registration function?? Is it just to make its value appear in the TPL?

The purpose of registration is to let Smarty find him, otherwise it will be wrong!

Plainly, it is registering a function that allows you to invoke it in the TPL.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.