码迷,mamicode.com
首页 > 其他好文 > 详细

Smarty模板技术/引擎——变量操作

时间:2015-11-13 06:13:06      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:

1,基本变量

$smarty->assign(‘data1‘,3);   
$smarty->assign(‘data2‘,3.45);
$smarty->assign(‘data3‘,‘fffff‘);
$smarty->assign(‘data41‘,true);
$smarty->assign(‘data42‘,false);

整数:<{ $data1 }><br/>
小数:<{ $data2 }><br/>
字符串:<{ $data3 }><br/>
布尔型true:<{ $data41 }><br/>
布尔型false:<{ $data42 }><br/>

输出如下:

技术分享

2,数组

//一维索引数组
$arr1=array("北京","上海","天津");
$smarty->assign(‘arr1‘,$arr1);

//一维关联数组
$arr2 = array("city1"=>"北京", "city2"=>"上海", "city3"=>"天津");
$smarty->assign(‘arr2‘,$arr2);

//二维索引数组
$arr3 = array(array("北京","上海","天津"),array("小倩","彩臣","老妖"));
$smarty->assign(‘arr3‘,$arr3);

//二维关联数组
$arr4 = array(
    array("id"=>"001","name"=>"liuhuayong","age"=>10),
    array("id"=>"002","name"=>"niexiaoqian","age"=>20),
    array("id"=>"003","name"=>"heishanlaoyao","age"=>30)
);
$smarty->assign(‘arr4‘,$arr4);

//二维关联数组
$arr5 = array(
    ‘emp1‘=>array("id"=>"001","name"=>"liuhuayong","age"=>10),
    ‘emp2‘=>array("id"=>"002","name"=>"niexiaoqian","age"=>20),
    ‘emp3‘=>array("id"=>"003","name"=>"heishanlaoyao","age"=>30)
);
$smarty->assign(‘arr5‘,$arr5);
一维索引数组:<{ $arr1[0] }>||<{ $arr1[1] }>||<{ $arr1[2] }><br/>
一维关联数组:<{ $arr2.city1 }>||<{ $arr2.city2 }>||<{ $arr2.city3 }><br/>
二维索引数组:<{ $arr3[1][1] }>||<{ $arr3[1][2] }><br/>
二维关联数组:<{ $arr4[1].id }>||<{ $arr4[1].name }>||<{ $arr4[1].age }><br/>
二维关联数组:<{ $arr5.emp1.id }>||<{ $arr5.emp1.name }>||<{ $arr5.emp1.age }><br/>

输出:

技术分享

3,对象

class dog{
    public $name;
    public $age;
    public function __construct($name,$age){
        $this->name = $name;
        $this->age = $age;
    }
}
$dog = new dog(‘花花‘,4);
$smarty->assign(‘dog‘,$dog);
对象:<{ $dog->name }>||<{ $dog->age }>

技术分享

 

Smarty模板技术/引擎——变量操作

标签:

原文地址:http://www.cnblogs.com/usa007lhy/p/4960765.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!