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?