Simple use of objects
The declaration of objects is the same as that of variables, and is declared through assign
Modify the test.php file:
<?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');
Modify the test.html file:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>test</title> </head> <body> <!--html的注释--> {*smarty模板的注释*} 我叫{$address->name}今年{$address->age}岁<br> </body> </html>
The running display is as follows: