<?php
include('libs/Smarty.class.php');
//程序目录
const DIR_SEP = DIRECTORY_SEPARATOR;
define('SITE_ROOT', dirname(__FILE__).DIR_SEP);
$smarty = new Smarty;
$smarty->template_dir = SITE_ROOT.'templates'.DIR_SEP;
$smarty->compile_dir = SITE_ROOT.'templates_c'.DIR_SEP;
$smarty->config_dir = SITE_ROOT.'configs'.DIR_SEP;
$smarty->cache_dir = SITE_ROOT.'cache'.DIR_SEP;
$smarty->assign('content','hello world!');
$smarty->assign(array("one"=>"11111","two"=>"2222"));
class Person {
public $name = "meizi";
public $sex ="nv";
public function say(){
echo "this is a {$this->name} and {$this->sex}";
return $this;
}
function eat(){
echo "good very";
}
}
$smarty -> assign("mz",new Person());
$smarty ->assign("arr1",array("one","two","three"));
$smarty ->assign("arr2",array("hello"=>array("one","two","three")));
$smarty->display('test.tpl');
?>
templates 目录下
{$content} </br>
{$content} </br>
{$content} </br>
{$content} </br>
{$content} </br>
{$one} </br>
{$two} </br>
{$mz->name} </br>
{$mz->say()->eat()}</br>
array diaoqu1 {$arr1[0]}</br>
ay diaoqu2 {$arr2['hello'][1]}</br>