赋值对象方法
html标签写法{$对象名->属性名/方法名()} 一般还是比较少用的
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>temp3</title>
</head>
<body>
<h1>{$man->name}</h1>
<h1>{$man->say()}</h1>
</body>
</html><?php
/*
assgin赋值对象
smarty配置简化(temp,comp地址)封装到类
*/
class man{
public $name='八郎';
public function say(){
echo 'what?my name is '.$this->name;
}
}
$man= new man();
<strong>require</strong>('../../smarty3/libs/Smarty.class.php');
<strong>require</strong>('./mysmarty.class.php');
$smarty=new MySmarty();
// 赋值对象
$smarty->assign('man',$man);
$smarty->display('temp4.html');
?>
<?php
class MySmarty extends Smarty{
/*$this->template_dir='./temp';
$this->compile_dir='./comp';
因为是父类私有属性,所以不能改写
smarty内部有开放的接口,setTemplateDir可修改*/
public function __construct(){
parent::__construct();
$this->setTemplateDir('./temp');
$this->setCompileDir('./comp');
}
}
以上就介绍了Smarty赋值对象方法,配置简化封装类,包括了require方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号