<?php
date_default_timezone_set("PRC");
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2017/4/9
* Time: 11:28
* 分配变量
* 数组变量
* //可以直接运算
* 超级全局变量{*配置文件的变量*}$smarty.get.id
*系统变量{$smarty.server.HTTP_HOST}
*/
require "smarty.inc.php";
global $_smarty;
define("PI","155");
$_title="smarty";
//分配变量
$_smarty->assign("title",$_title);
//数组变量
//普通数字下标数组{$array[0]}
$_array=array("zpengkai","李志军","伟哥");
//如果是关联数组 字符串下标
$_array2=array("nihao"=>"zpengkai","nihao2"=>"李志军","dage"=>"伟哥");
$_smarty->assign("name",$_array2);
$_array3=array(
array("zpengkai","李志军","伟哥"),
array("zpengkai","李志军","伟哥")
);
$_array4=array(
"qq"=> array("zpengkai","李志军","伟哥"),
"tentxun"=> array("zpengkai","李志军","伟哥")
);
$_smarty->assign("name",$_array3);
$_smarty->assign("name",$_array4);
class Computer{
public $_name="彭开开";
public function run(){
echo "正在运行....";
}
}
$_smarty->assign("name",new Computer());
//可以直接运算
$_smarty->assign("x",20);
$_smarty->assign("y",30);
$_smarty->display("demo2.tpl");
demo02.tpl
{config_load file="config.conf"}
<html>
<head>
<title>{$title}</title>
</head>
<script>
</script>
<body>
{*
{$name[2]}
{$name.nihao2}
{$name[1][0]}
{$name.qq[1]}
{$name->_name}
{$x+$y}
{$name->run()}*}
{*配置文件的变量*}
{*{$smarty.config.webname}
{#webname#}*}
{*{$smarty.get.id}*}
{*{$smarty.server.HTTP_HOST}*}
{$smarty.const.PI}
</body>
</html>