您的位置:首页 > 其它

有关 关联数组、索引数组、对象在Smarty中的应用

2012-11-19 20:09 204 查看
php文件

<?php

$address = array('北京','天津','河北');

$birthday = array(year=>'1990',month=>'12',day=>array('1',"星期一"));

class Stu{

var $name;

var $sex;

var $age;

function study(){

echo "好好学习,天天向上!";

}

}

$stu1 = new Stu;

$stu1->name ="张三";

$stu1->age="12";

$stu1->sex="女";

include("libs/Smarty.class.php");

$smarty= new Smarty();

$smarty->template_dir="demo/templates";

$smarty->compile_dir="demo/templates_c";

$smarty->left_delimiter="<{";

$smarty->right_delimiter="}>";

$smarty->assign("name","周少杰");

$smarty->assign("arr",$address);

$smarty->assign("birthday",$birthday);

$smarty->assign("student",$stu1);

$smarty->display("test.tpl");

?>

tpl文件

hello!<br />

你好!<br />

我是<{$name}>!<br />

归属地:

<select>

<option><{$arr[0]}></option>

<option><{$arr[1]}></option>

<option><{$arr[2]}></option>

</select><br>

出生年月:

<{$birthday.year}>年<{$birthday.month}>月<{$birthday.day[0]}>日<{$birthday.day[1]}><br>

我是:<{$student->name}>,<{$student->age}>岁<br />

性别:<{$student->sex}><br />

我的宣言是:<{$student->study()}><br />
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: