abstract:<?php require __DIR__ .'/config/config.php'; $name = '杨俊杰'; $array = ['杨','军','杰']; $res = [ 'name'=>'杨俊杰', 'age'=>
<?php
require __DIR__ .'/config/config.php';
$name = '杨俊杰';
$array = ['杨','军','杰'];
$res = [
'name'=>'杨俊杰',
'age'=>'18',
'sex'=>'小哥哥'
];
$data = [
['name'=>'张无忌','age'=>19,'sex'=>'男'],
['name'=>'周芷若','age'=>19,'sex'=>'女'],
['name'=>'赵敏','age'=>19,'sex'=>'女']
];
$_POST['user_name'] = '超级管理员';
$_GET['page'] = 10;
$_SESSION['pass'] = sha1(123456);
//不用调用 assign()进行模板赋值,可以直接在模板中输出
function Qian($a,$b){
return $a+$b;
}
const NAME = '杨俊杰要努力';
class Marty
{
public $name = '杨俊杰';
public function getSex(){
return '小哥哥叫'.$this->name;
}
}
$Marty = new Marty();
$smarty->assign('name',$name);//给模板绑定变量
$smarty->assign('array',$array);
$smarty->assign('res',$res);
$smarty->assign('Marty',$Marty);
$smarty->assign('data',$data);
$smarty->display('index.html');//渲染模板
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<p>
今晚消费由{$Marty->name}买单。
今晚消费由{$Marty->getSex()}买单,尖叫声。
</p>
<ul>
<li>{$data.1.name}</li>
<li>{$data.0.name}</li>
<li>{$data.2.name}</li>
</ul>
<h2>
您的余额为{Qian(1,2)}
</h2>
<h3>{$smarty.const.NAME}</h3>
<p>POST提交的用户名是:{$smarty.post.user_name}</p>
<p>GET传入当前页数是:{$smarty.get.page}</p>
<p>SESSION回话中的密码是:{$smarty.session.pass}</p>
</body>
</html>
Correcting teacher:天蓬老师Correction time:2019-03-25 09:12:29
Teacher's summary:模板变量的赋值, 是所有模板引擎都具有的基本功能, 赋值的方式很多的, 方法只是其中之一