物件的簡單使用
物件的宣告和變數一樣,透過assign來宣告
修改test.php檔:
<?php require "./libs/Smarty.class.php"; $smarty = new Smarty; class Person{ public $name="smile"; public $age=25; } $person=new Person(); $smarty->assign('address',$person); $smarty->display('./templates/test.html');
修改test.html檔:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>test</title> </head> <body> <!--html的注释--> {*smarty模板的注释*} 我叫{$address->name}今年{$address->age}岁<br> </body> </html>
執行展示如下: