간단한 객체 사용로그인

간단한 객체 사용

객체 선언은 변수 선언과 동일하며 할당을 통해 선언됩니다

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>

실행 화면은 다음과 같습니다.

微信图片_20180312153413.png

다음 섹션
<?php echo "对象的使用";
코스웨어