有关 关联数组、索引数组、对象在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 />
<?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 />
相关文章推荐
- 类中属性返回形式(对象,关联数组,索引数组)
- PHP索引数组转换成json是数组,php关联数组转换成json是对象。
- php将结果集匹配成索引数组、关联数组、对象的区别&&location对象
- Object - C运行时应用(二)—— 使用对象关联为分类增加属性(每个对象的属性互不干扰)
- for in在对象和数组中的应用
- smarty 遍历二维关联数组
- JavaScript对象之关联数组
- javascript 中获取对象的长度(map对象的长度)--js关联数组的长度
- 将数据库常用的操作(连接数据库,获得所有数据,获得一条记录,获得一列记录,获得一条索引数组,获得一条关联数组)都给封装到db.class.php里面,谁需要谁继承这个类 注意:提交封装的类文件
- PHP模板引擎Smarty应用(2)使用数组
- [JAVA]有关比较器(Comparator接口)的用法及对象数组排序问题
- C++ 与“类”有关的注意事项总结(十):类对象数组初始化(三种方法)
- JavaScript 中有关数组对象的方法
- 有关Java中数组和反射的应用
- 关联数组和顺序数组的应用场景
- Runtime应用(二)使用对象关联为分类增加属性(每个对象的属性互不干扰)
- C#:浅谈对象数组,运算符重载和深度复制的应用
- smarty 循环一维关联数组
- JavaScript 中有关数组对象的方法(详解)
- c++中矩阵相乘(对象数组与对象指针的应用)