A smarty about the problem of a hero

Source: Internet
Author: User
Ask your heroes a smarty question
Title, here is the source code:
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:




<title>Insert Title here</title>


<{myname name= "xxx"}>


----------------------------------------------------
Why access to index.php has been an error, errors are 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 index.php is replaced as follows, 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 an array of attributes when using the <{myname}> function
if (Isset ($param [' name '])) {
if ("Xu Xiao shrimp" = = $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");
?>
Ask the high finger to teach ...

------Solution--------------------
Do not understand ~ ~ are used in PHP processing, with Smarty display only ~
Array (& $object, $method) Form, 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.