Home > Backend Development > PHP Tutorial > Smarty assignment object method, configure simplified encapsulation class

Smarty assignment object method, configure simplified encapsulation class

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-29 09:13:22
Original
1029 people have browsed it

Assignment object method

html tag writing method {$object name->attribute name/method name ()} is generally less used

<!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>
Copy after login

<?php
/*
assgin赋值对象
smarty配置简化(temp,comp地址)封装到类
*/
class man{
	public $name=&#39;八郎&#39;;
	public function say(){
		echo &#39;what?my name is &#39;.$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');

?>
Copy after login

Configuration simplified encapsulation class class.php
<?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');
	}
}
Copy after login

The above introduces the Smarty assignment object method, configures the simplified encapsulation class, including the require content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template