Question about a Smarty project-php Tutorial

Source: Internet
Author: User
Ask you a question about Smarty. The following is the source code: index. php: & lt ;? Phpincludemain. inc. php; & nbsp; header (& quot; Content-Type: texthtml; charsetUTF-8 & quot;); & nbsp; $ sm-& gt; assign (& quot; time & quot;, d ask you a question about Smarty
For example, the source code is as follows:
Index. php:
Include 'main. inc. php ';
Header ("Content-Type: text/html; charset = UTF-8 ");
$ Sm-> assign ("time", date ("Y-m-d H-I-s "));
Class User {
Function smarty_function_myname ($ param, & $ smarty ){
If (isset ($ param ['name']) {
If ("xxx" = $ param ['name']) {
Return "I know ".
} Else {
Return "I don't know you! ";
}
}
}
}
$ User = new User ();
$ Sm-> register_function ("myname", array ($ user, "smarty_function_myname "));
$ Sm-> display ("index. tpl ");
?>
--------------------------------------------------------------------
Index. tpl:




Insert title here


<{Myname name = "xxx"}>


----------------------------------------------------
Why is an error always reported when accessing index. php? the error is as follows:
Fatal error: Call to undefined function smarty_function_myname () in F: \ AppServ \ www \ Demo \ templates_c \ % 45 ^ 45E ^ 45E480CD % index. tpl. php on line 12

PS: If you change index. php to the following, it can be used normally:
Include 'main. inc. php ';
Header ("Content-Type: text/html; charset = UTF-8 ");
Function smarty_function_myname ($ param, & $ smarty ){
// $ Param is the attribute array when the <{myname}> function is used
If (isset ($ param ['name']) {
If ("Xu Xiaoxiao" ==$ param ['name']) {
Return "I know". date ("Y-m-d H-I-s ");
} Else {
Return "I don't know you! ";
}
}
}

$ Sm-> register_function ("myname", "smarty_function_myname ");
$ Sm-> display ("index. tpl ");
?>
Please advise me...

------ Solution --------------------
Not understand ~~ Php is used for processing, and smarty is used for display ~
Array (& $ object, $ method) array, where & $ object is a reference to an object, and $ method is a method of it;
Will it be $ sm-> register_function ("myname", array (& $ user, "smarty_function_myname?

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.