thinkPHP 模板操作
1.assign赋值
$this->assign('title','模板操作');
$this->assign('bests',$bests);//$bests是二维数组
2.变量的输出
在Html代码中输出标题如下:
<title>{$title}</title>
注意:TP的模板标签和smarty稍有不同
TP在控制结构/循环/if/else时,用<>
而最具体的输出变量 用{$标签}
3.if/else标签
/* //if
public function ve(){
$a = mt_rand(3,6);
$this->assign('ff',$a);
$this->display();
}
*/
/*
//三元运算符
public function ve(){
$a = mt_rand(3,6);
$this->assign('ff',1);
$this->display();
}
// */
//数组
public function ve(){
$a = array(
array('id'=>1,'title'=>'中国123'),
array('id'=>2,'title'=>'中国456'),
array('id'=>3,'title'=>'中国789'),
); $this->assign('ff',$a);
$this->display();
}
在home/view/index目录下创建ve.html
<include file = "Public/head"/>
<body>
<!--
<h1> {$ff?'hello world':00000}<br/>
//if的操作
<if condition = "$ff eq 5">
{$ff}
<else/>{$ff}000
</if> </h1>
-->
//数组的遍历
<foreach name='ff' item="v">
{$v.title}<br/>
</foreach>
</body>
</html>
4.import导入css,js文件
在home/view/Index/ve.html
<head>
<!--
<import type="css" file="a.demo" />
<import type="js" file="cs" />
--> <load href = "__PUBLIC__/cs.js" />
</head>
<body>
<!--
<h1> {$ff?'hello world':00000}<br/> <if condition = "$ff eq 5">
{$ff}
<else/>{$ff}000
</if> </h1>
-->
<foreach name='ff' item="v">
{$v.title}<br/>
</foreach>
</body>
新建一个Public文件夹

Public里面放入需要引入的文件

5.load导入css,js文件
在home/view下建一个public文件夹

里面是需要引入的头文件

在Home/view/index目录下引入public文件目录下的模块

代码如下
ve.html
<include file = "Public/head"/>
<body> </body>
</html>
head.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<!--
<import type="css" file="a.demo" />
<import type="js" file="cs" />
--> <load href = "__PUBLIC__/cs.js" />
</head> <body> </body>
</html>
效果图

6.不要让模板做太多的工作!
功能:输出数据,而非处理数据
应该由控制器来处理
thinkPHP 模板操作的更多相关文章
- [转]thinkphp 模板显示display和assign的用法
thinkphp 模板显示display和assign的用法 $this->assign('name',$value); //在 Action 类里面使用 assign 方法对模板变量赋值,无论 ...
- thinkPHP 模板的使用技巧(十三)
原文:thinkPHP 模板的使用技巧(十三) 模板的使用技巧:页面跳转 .模板包含.模板渲染.模板的继承 页面跳转 <a href='__URL__/index'>我要跳转到首页面,用这 ...
- Thinkphp模板简单入门
Thinkphp模板概述: ThinkPHP内置了一个基于XML的性能卓越的模板引擎,这是一个专门为ThinkPHP服务的内置模板引擎,使用了XML标签库技术的编译型模板引擎,支持两种类型的模板标签, ...
- thinkphp模板中,checkbox回显问题
thinkphp 模板里面可以这样写包含操作 //in 标签 <in name="变量名" value="值1,值2,...">要输出的内容< ...
- thinkphp模板常用的方法
thinkphp模板我是看了3.2的文档,对里面的东西过了一遍,然后在写到需要用到模板的东西的时候就有印象,有的能直接回顾,但是有的就可能只知道有这个东西,但是不知道怎么用,所以就重新查手册,这个的话 ...
- ThinkPHP 模板substr的截取字符串函数
ThinkPHP 模板substr的截取字符串函数在Common/function.php加上以下代码 /** ** 截取中文字符串 **/ function msubstr($str, $start ...
- OpenCV2邻域和模板操作
在图像处理中,通过当前位置的邻域像素计算新的像素值是很常见的操作.当邻域包含图像的上几行和下几行时,就需要同时扫描图像的若干行,这就是图像的邻域操作了.至于模板操作是实现空间滤波的基础,通常是使用一个 ...
- Thinkphp 模板中直接对数据处理 模板中使用函数 中文字符串截取
1.Thinkphp 模板中直接对数据处理:{$data.name|substr=0,3} 2.中文字符串截取函数:mb_substr=0,14,'utf-8' 3.中文字符串统计:iconv_str ...
- ThinkPHP 模板判断输出--Switch 标签
ThinkPHP 模板引擎支持 switch 判断,根据不同情况输出不同的值,格式如下:<switch name="变量名" > <case value=& ...
随机推荐
- springJDBC01 利用springJDBC操作数据库
1 什么是springJDBC spring通过抽象JDBC访问并一致的API来简化JDBC编程的工作量.我们只需要声明SQL.调用合适的SpringJDBC框架API.处理结果集即可.事务由Spri ...
- PythonNote02_HTML标签
<!DOCTYPE> <html> <head> <meta charset = "utf-8" /> <meta name= ...
- 34- 24 Point game
http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=43 24 Point game 时间限制:3000 ms | 内存限制:65535 KB ...
- 项目一:在线下单(补充) activeMQ使用(重点) 重构客户注册功能,发短信功能分离
1 课程计划 1.在线下单(补充) 2.activeMQ使用(重点) n 简介和安装 n activeMQ入门案例 n spring整合activeMQ应用 3.重构客户注册功能,发短信功能分离 n ...
- ROS Learning-004 beginner_Tutorials 介绍简单的ROS命令
ROS Indigo beginner_Tutorials-03 介绍简单的ROS命令 我使用的虚拟机软件:VMware Workstation 11 使用的Ubuntu系统:Ubuntu 14.04 ...
- 数学基础-3D空间的位置表示
转自:http://www.cnblogs.com/gaoxiang12/p/5113334.html 刚体运动 本篇讨论一个很基础的问题:如何描述机器人的位姿.这也是SLAM研究的一个很基本的问题. ...
- Entity Framework Tutorial Basics(22):Disconnected Entities
Disconnected Entities: Before we see how to perform CRUD operation on disconnected entity graph, let ...
- enumerate()函数
for index,value in enumerate(list): print index,value 等于for i in range(0,len(list)): print i,l ...
- arp绑定
Windows xp 在CMD中执行 arp -s ip mac 例如 arp -s 192.168.2.101 40-5f-c2-c1-97-fb Windwos 7 在 Windows 7/Vis ...
- url-pattern 的设置与匹配