一、模板变量赋值 php
$this->assign('name',$value); //或者下面的写法: $this->name = $value;二、变量输出
$this->display();三、页面显示
{$变量名称}
<body> <p>用 户 名:{$username}</p> <p>电子邮件:{$userinfo["email"]}</p> <p>注册时间:{$userinfo["regdate"]|date="Y-m-d H:i",###}</p> </body>
volist 标签用于在模板中循环输出数据集或者多维数组
mod:记录对mod求余
$key:显示数组的key值
$k:显示对数组循环的次数
offset:从第5条开始循环
length:循环10条数据 html
<table> <volist name="list" id="vo" mod="2" key="k" offset=5 length=10> <tr<eq name="mod" value="0"> style="background-color:#FFF;"</eq>> <td>{$k}{$key}我是单元格内容</td> <td>{$k}{$key}我也是单元格内容</td> </tr> </volist> </table>多维数组循环参考:http://www.5idev.com/p-thinkphp_tpl_volist_nested_loop.shtml
foreach标签没有volist标签那么多的功能,优点是能够对对象进行遍历输出,而volist标签一般是用于输出数组。
thinkphp
<foreach name="list" id="vo"> 用 户 名:{$vo.username}<br /> 电子邮件:{$vo.email}<br /> 注册时间:{$vo.regdate|date="Y-m-d H:i",###} <hr /> </foreach>
name 属性值为变量名称,也就是没有 $ 符号,而 value 值使用变量时须要 $ 符号,case 的 value 属性能够支持多个条件的同时判断,使用 | 符号进行分割 数组
<switch name="uid"> <case value="$adminId">管理员</case> <case value="gif|png|jpeg">图像格式文件</case> <default />群众 </switch>
一、比较标签 ide
<比较标签 name="变量名" value="值">输出的内容</比较标签>例如:
<eq name="username" value="admin">管理员</eq>二、present标签、notpresent标签
<present name="变量名">要输出的内容</present>notpresent 标签,为 present 标签的反义(即 !isset() )
三、defined标签、notdefined标签 函数
<defined name="SITE_NAME">网站名称:{*SITE_NAME}</defined>
该例子等同于: oop
<?php if(defined("SITE_NAME")){ echo '网站名称:',constant("SITE_NAME"); } ?>四、empty标签、notempty标签
<empty name="username">username 为空值</empty>
该例子等同于: 布局
<?php if(empty($username)){ echo 'username 为空值'; } ?>
根据 empty() 函数咱们知道,以下这些状况获得的结果都是 TRUE 的(使用 empty 标签会有输出): 网站
//假设要检测的变量为 $x $x = ""; $x = null; var $x; $x = array(); $x = false; $x = 0; $x = "0";五、in标签、notin标签
<in name="groupId" value="1,2,3">管理群组</in>
该例子等同于: ui
<?php if(in_array(($groupId), explode(',',"1,2,3"))){ echo '管理群组'; } ?>六、if...else标签
<if condition="($vo['uid'] eq 1) OR ($vo['username'] eq 'admin') ">管理员 <elseif condition="$vo['uid'] gt 1" />群众 <else />游客 </if>
condition 属性里面还支持直接使用php代码,例如:
<if condition="strtoupper($vo['username']) eq 'ADMIN' ">管理员 <else />群众 </if>
redirect 方法语法以下:
$this->redirect(string url, array params, int delay, string msg)例子:
class IndexAction extends Action{ public function index(){ $this->redirect('select', array('status'=>1), 3, '页面跳转中~'); } }
重定向后获得的 URL 可能为:http://www.5idev.com/index.php/Index/select/status/1
// 不延时,直接重定向 $this->redirect('select', array('status'=>1)); // 延时跳转,但不带参数,输出默认提示 $this->redirect('select', '', 3); // 重定向到其余模块操做 $this->redirect('Public/login'); // 重定向到其余分组 $this->redirect('Admin-Public/login');success()和error()是经过<meta http-equiv="refresh" content="3">意思是隔3秒钟后刷新.
方法:
$this->方法名("变量名",["过滤方法"],["默认值"])例子:
$this->_get("name");// htmlspecialchars($_GET["name"]) $this->_get("name","strip_tags"); $this->_get("id","strip_tags",0); $this->_get('id',false);//没有过滤方法(默认的也不使用)能够在配置文件中设置默认过滤方法:
'DEFAULT_FILTER'=>'htmlspecialchars,strip_tags'
方法 | 说明 |
---|---|
isGet | 判断是不是GET方式提交 |
isPost | 判断是不是POST方式提交 |
isPut | 判断是不是PUT方式提交 |
isDelete | 判断是不是DELETE方式提交 |
isHead | 判断是不是HEAD提交 |
{__CONTENT__}
若是项目须要使用不一样的布局模板,能够动态的配置LAYOUT_NAME参数实现。
若是某些页面不须要使用布局模板功能,能够在模板文件开头加上 {__NOLAYOUT__} 字符串。
二、以当前输出模板为入口的方式
在模板页中添加
<layout name="layout" />