本文實例講述了smarty高級特性之對象的使用方法。分享給大家供大家參考,具體如下:
<?php
include_once('smarty.inc.php');
class Dog{
public $name;
public function sayHello(){
echo 'hello';
}
}
$dog1=new Dog();
$dog1->name="first dog";
$smarty->assign("dog",$dog1);
$smarty->display('test.tpl');
?>
test.tpl文件:
屬性調用:{$dog->name}<br />
方法調用:{$dog->sayHello()}
輸出顯示:
first dog
hello
希望本文所述對大家基於smarty的PHP程序設計有所幫助。