thinkphp的模板文件放置在/home/View下这里的模板文件需要跟控制器的名称一致
例如在view目录下新建一个Index目录那么Index控制器就会调用这个目录的模板文件
新建Index目录里面在创建index.html内容如下

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>天蝎</title>
</head>
<body>
<p>helloworld</p></body>
</html>

改写IndexController.class.php的index方法

<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {public function index(){$this->display();}?>

display方法是用来调用模板文件的访问index.php/home/index/index就能访问到Index目录下index.html模板
可以在display中添加参数来指定需要访问的模板文件

<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {public function index(){$this->display();}public function test(){$this->display("index");;}
}

当我们访问index.php/home/index/test实际上访问到的还是index.html模板因为我们在display指定了

模板常用静态变量
PUBLIC 它代表的是/Public这个目录这个目录是用来存放css js样式文件的
/home/view/Index/index.html

<!doctype html>
<html>
<head><meta charset="UTF-8"/><title>简单通用文章系统后台管理模板</title><link rel="stylesheet" type="text/css" href="__PUBLIC__/css/common.css"/><link rel="stylesheet" type="text/css" href="__PUBLIC__ /css/main.css"/>
</head>
<body>
<div class="topbar-wrap white"><div class="topbar-inner clearfix"><div class="topbar-logo-wrap clearfix"><h1 class="topbar-logo none"><a href="index.html" class="navbar-brand">后台管理</a></h1><ul class="navbar-list clearfix"><li><a class="on" href="index.html">首页</a></li><li><a href="#" target="_blank">网站首页</a></li></ul></div><div class="top-info-wrap"><ul class="top-info-list clearfix"><li><a href="#">管理员</a></li><li><a href="#">修改密码</a></li><li><a href="#">退出</a></li></ul></div></div>
</div>
<div class="container clearfix"><div class="sidebar-wrap"><div class="sidebar-title"><h1>菜单</h1></div><div class="sidebar-content"><ul class="sidebar-list"><li><a href="#"><i class="icon-font">&#xe003;</i>常用操作</a><ul class="sub-menu"><li><a href="design.html"><i class="icon-font">&#xe008;</i>作品管理</a></li><li><a href="design.html"><i class="icon-font">&#xe005;</i>博文管理</a></li><li><a href="design.html"><i class="icon-font">&#xe006;</i>分类管理</a></li><li><a href="design.html"><i class="icon-font">&#xe004;</i>留言管理</a></li><li><a href="design.html"><i class="icon-font">&#xe012;</i>评论管理</a></li><li><a href="design.html"><i class="icon-font">&#xe052;</i>友情链接</a></li><li><a href="design.html"><i class="icon-font">&#xe033;</i>广告管理</a></li></ul></li><li><a href="#"><i class="icon-font">&#xe018;</i>系统管理</a><ul class="sub-menu"><li><a href="system.html"><i class="icon-font">&#xe017;</i>系统设置</a></li><li><a href="system.html"><i class="icon-font">&#xe037;</i>清理缓存</a></li><li><a href="system.html"><i class="icon-font">&#xe046;</i>数据备份</a></li><li><a href="system.html"><i class="icon-font">&#xe045;</i>数据还原</a></li></ul></li></ul></div></div><!--/sidebar--><div class="main-wrap"><div class="crumb-wrap"><div class="crumb-list"><i class="icon-font">&#xe06b;</i><span>欢迎使用『豪情』博客程序,建博的首选工具。</span></div></div><div class="result-wrap"><div class="result-title"><h1>快捷操作</h1></div><div class="result-content"><div class="short-wrap"><a href="insert.html"><i class="icon-font">&#xe001;</i>新增作品</a><a href="insert.html"><i class="icon-font">&#xe005;</i>新增博文</a><a href="insert.html"><i class="icon-font">&#xe048;</i>新增作品分类</a><a href="insert.html"><i class="icon-font">&#xe041;</i>新增博客分类</a><a href="#"><i class="icon-font">&#xe01e;</i>作品评论</a></div></div></div><div class="result-wrap"><div class="result-title"><h1>系统基本信息</h1></div><div class="result-content"><ul class="sys-info-list"><li><label class="res-lab">操作系统</label><span class="res-info">WINNT</span></li><li><label class="res-lab">运行环境</label><span class="res-info">Apache/2.2.21 (Win64) PHP/5.3.10</span></li><li><label class="res-lab">PHP运行方式</label><span class="res-info">apache2handler</span></li><li><label class="res-lab">静静设计-版本</label><span class="res-info">v-0.1</span></li><li><label class="res-lab">上传附件限制</label><span class="res-info">2M</span></li><li><label class="res-lab">北京时间</label><span class="res-info">2014年3月18日 21:08:24</span></li><li><label class="res-lab">服务器域名/IP</label><span class="res-info">localhost [ 127.0.0.1 ]</span></li><li><label class="res-lab">Host</label><span class="res-info">127.0.0.1</span></li></ul></div></div><div class="result-wrap"><div class="result-title"><h1>使用帮助</h1></div><div class="result-content"><ul class="sys-info-list"><li><label class="res-lab">更多模板:</label><span class="res-info"><a href="http://www.codejie.net/" target="_blank">源码街-免费源码下载</a></span></li></ul></div></div></div><!--/main-->
</div>
</body>
</html>

创建头部模板在view目录下创建comm目录在创建head.html
/home/view/comm/head.html

<!doctype html>
<html>
<head><meta charset="UTF-8"/><title>后台管理</title><link rel="stylesheet" type="text/css" href="__PUBLIC__/css/common.css"/><link rel="stylesheet" type="text/css" href="__PUBLIC__/css/main.css"/>
</head>
<body>
<div class="topbar-wrap white"><div class="topbar-inner clearfix"><div class="topbar-logo-wrap clearfix"><h1 class="topbar-logo none"><a href="index.html" class="navbar-brand">后台管理</a></h1><ul class="navbar-list clearfix"><li><a class="on" href="index.html">首页</a></li><li><a href="#" target="_blank">网站首页</a></li></ul></div><div class="top-info-wrap"><ul class="top-info-list clearfix"><li><a href="#">管理员</a></li><li><a href="#">修改密码</a></li><li><a href="#">退出</a></li></ul></div></div>
</div>
<div class="container clearfix"><div class="sidebar-wrap"><div class="sidebar-title"><h1>菜单</h1></div><div class="sidebar-content"><ul class="sidebar-list"><li><a href="#"><i class="icon-font">&#xe003;</i>常用操作</a><ul class="sub-menu"><li><a href="design.html"><i class="icon-font">&#xe008;</i>作品管理</a></li><li><a href="design.html"><i class="icon-font">&#xe005;</i>博文管理</a></li><li><a href="design.html"><i class="icon-font">&#xe006;</i>分类管理</a></li><li><a href="design.html"><i class="icon-font">&#xe004;</i>留言管理</a></li><li><a href="design.html"><i class="icon-font">&#xe012;</i>评论管理</a></li><li><a href="design.html"><i class="icon-font">&#xe052;</i>友情链接</a></li><li><a href="design.html"><i class="icon-font">&#xe033;</i>广告管理</a></li></ul></li><li><a href="#"><i class="icon-font">&#xe018;</i>系统管理</a><ul class="sub-menu"><li><a href="system.html"><i class="icon-font">&#xe017;</i>系统设置</a></li><li><a href="system.html"><i class="icon-font">&#xe037;</i>清理缓存</a></li><li><a href="system.html"><i class="icon-font">&#xe046;</i>数据备份</a></li><li><a href="system.html"><i class="icon-font">&#xe045;</i>数据还原</a></li></ul></li></ul></div></div>

在/home/view/index.html中直接包含这个头部模板

<include file="comm/head" /><!--/sidebar--><div class="main-wrap"><div class="crumb-wrap"><div class="crumb-list"><i class="icon-font">&#xe06b;</i><span>欢迎使用『豪情』博客程序,建博的首选工具。</span></div></div><div class="result-wrap"><div class="result-title"><h1>快捷操作</h1></div><div class="result-content"><div class="short-wrap"><a href="insert.html"><i class="icon-font">&#xe001;</i>新增作品</a><a href="insert.html"><i class="icon-font">&#xe005;</i>新增博文</a><a href="insert.html"><i class="icon-font">&#xe048;</i>新增作品分类</a><a href="insert.html"><i class="icon-font">&#xe041;</i>新增博客分类</a><a href="#"><i class="icon-font">&#xe01e;</i>作品评论</a></div></div></div><div class="result-wrap"><div class="result-title"><h1>系统基本信息</h1></div><div class="result-content"><ul class="sys-info-list"><li><label class="res-lab">操作系统</label><span class="res-info">WINNT</span></li><li><label class="res-lab">运行环境</label><span class="res-info">Apache/2.2.21 (Win64) PHP/5.3.10</span></li><li><label class="res-lab">PHP运行方式</label><span class="res-info">apache2handler</span></li><li><label class="res-lab">静静设计-版本</label><span class="res-info">v-0.1</span></li><li><label class="res-lab">上传附件限制</label><span class="res-info">2M</span></li><li><label class="res-lab">北京时间</label><span class="res-info">2014年3月18日 21:08:24</span></li><li><label class="res-lab">服务器域名/IP</label><span class="res-info">localhost [ 127.0.0.1 ]</span></li><li><label class="res-lab">Host</label><span class="res-info">127.0.0.1</span></li></ul></div></div><div class="result-wrap"><div class="result-title"><h1>使用帮助</h1></div><div class="result-content"><ul class="sys-info-list"><li><label class="res-lab">更多模板:</label><span class="res-info"><a href="http://www.codejie.net/" target="_blank">源码街-免费源码下载</a></span></li></ul></div></div></div><!--/main-->
</div>
</body>
</html>

/home/view/comm/insert.html

<include file="comm/head" /><!--/sidebar--><div class="main-wrap"><div class="crumb-wrap"><div class="crumb-list"><i class="icon-font"></i><a href="/jscss/admin/design/">首页</a><span class="crumb-step">&gt;</span><a class="crumb-name" href="/jscss/admin/design/">作品管理</a><span class="crumb-step">&gt;</span><span>新增作品</span></div></div><div class="result-wrap"><div class="result-content"><form action="/jscss/admin/design/add" method="post" id="myform" name="myform" enctype="multipart/form-data"><table class="insert-tab" width="100%"><tbody><tr><th width="120"><i class="require-red">*</i>分类:</th><td><select name="colId" id="catid" class="required"><option value="">请选择</option><option value="19">精品界面</option><option value="20">推荐界面</option></select></td></tr><tr><th><i class="require-red">*</i>标题:</th><td><input class="common-text required" id="title" name="title" size="50" value="" type="text"></td></tr><tr><th>作者:</th><td><input class="common-text" name="author" size="50" value="admin" type="text"></td></tr><tr><th><i class="require-red">*</i>缩略图:</th><td><input name="smallimg" id="" type="file"><!--<input type="submit" onclick="submitForm('/jscss/admin/design/upload')" value="上传图片"/>--></td></tr><tr><th>内容:</th><td><textarea name="content" class="common-textarea" id="content" cols="30" style="width: 98%;" rows="10"></textarea></td></tr><tr><th></th><td><input class="btn btn-primary btn6 mr10" value="提交" type="submit"><input class="btn btn6" onClick="history.go(-1)" value="返回" type="button"></td></tr></tbody></table></form></div></div></div><!--/main-->
</div>
</body>
</html>

thinkphp模板的使用相关推荐

  1. php中template函数,thinkPHP模板中函数的使用方法

    这篇文章主要介绍了thinkPHP模板中函数的使用方法,结合实例形式对比分析了php函数的单独使用与thinkPHP模板中php函数的相应使用技巧,需要的朋友可以参考下 1.php中的方法使用 $va ...

  2. ThinkPHP 模板循环输出 Volist 标签

    2019独角兽企业重金招聘Python工程师标准>>> volist 标签用于在模板中循环输出数据集或者多维数组. volist 标签 在模块操作中,select() 方法返回的是一 ...

  3. [转]thinkphp 模板显示display和assign的用法

    thinkphp 模板显示display和assign的用法 $this->assign('name',$value); //在 Action 类里面使用 assign 方法对模板变量赋值,无论 ...

  4. php代码getsubstr,ThinkPHP 模板substr的截取字符串函数实例讲解

    ThinkPHP 模板substr的截取字符串函数详解 ThinkPHP 模板substr的截取字符串函数 在Common/function.php加上以下代码 /** ** 截取中文字符串 **/ ...

  5. ThinkPHP 模板循环语法

    volist 标签 在模块操作中,select() 方法返回的是一个二维数组,可以用 volist 直接输出: <volist name="list" id="vo ...

  6. php字符串分割tp模板,ThinkPHP 模板substr的截取字符串函数详解

    ThinkPHP 模板substr的截取字符串函数 在Common/function.php加上以下代码 /** ** 截取中文字符串 **/ function msubstr($str, $star ...

  7. php向前截取字符串函数,ThinkPHP 模板substr的截取字符串函数详解

    ThinkPHP 模板substr的截取字符串函数 在Common/function.php加上以下代码 /** ** 截取中文字符串 **/ function msubstr($str, $star ...

  8. php 模板 自定义函数调用,thinkphp模板中使用自定义函数

    注意:自定义函数要放在项目应用目录/common/common.php中. 这里是关键. 模板变量的函数调用格式:{$varname|function1|function2=arg1,arg2,### ...

  9. thinkphp模板常用的方法

    thinkphp模板我是看了3.2的文档,对里面的东西过了一遍,然后在写到需要用到模板的东西的时候就有印象,有的能直接回顾,但是有的就可能只知道有这个东西,但是不知道怎么用,所以就重新查手册,这个的话 ...

  10. php volist中作判断,ThinkPHP模板中判断volist循环的最后一条记录的验证方法

    ThinkPHP模板中判断volist循环的最后一条记录的验证方法 对于用过smarty做过php开发的朋友来说,应该都知道在smarty模板里面判断foreach循环是否是最后一个可以用$smart ...

最新文章

  1. android系统密码设置功能,手机锁屏密码怎么设置 三种安卓手机锁屏方式推荐
  2. 多线程EXecutor 柜架示例
  3. 反转链表的golang实现
  4. 信阳农林技术学院经纬度_信阳农林学院全景-360度,720度,高清全景地图-expoon网展...
  5. 字符串加括号问题(矩阵乘法组合问题)C++
  6. Python学习笔记:Day 7 编写MVC
  7. Rose2003的安装和破解
  8. WordPress的nocache header生成原理
  9. php拖拽原理,JS拖拽原理
  10. 使用oracle sql profile固定执行计划
  11. 前言 第一章 为什么要培养好习惯
  12. Intel® Extreme Tuning Utility (Intel® XTU)服务 xtu无法自动启动的问题
  13. UDP的单播广播和组播
  14. js的json php无法json_decode,PHP中遇到BOM、 编码导致json_decode函数无法解析问题
  15. 网线8芯线各自作用是什么?几种常用的网线定义行业标准
  16. 【linux命令学习】— cut 和 tr 命令学习
  17. Windows 10的最新版本是什么?
  18. chromosome-territories:染色质疆域简介
  19. Is the influences futural AI bring to software engineers are that scary?
  20. 互联网查询信用报告,为什么提示“无法进行注册”?

热门文章

  1. 〖Python零基础入门篇⑦〗- Python 的脚本结构
  2. c语言笔记5-数组和指针
  3. 2021-2025年中国家用电器消耗品行业市场供需与战略研究报告
  4. pts 和 tty 的区别
  5. 关于U盘插入电脑被识别却在我的电脑里显示不出来的解决办法-秋天的风的博客
  6. Java数据结构——栈(数组实现)
  7. UE4【虚幻引擎4实用技巧】-关于为道具添加稀有度
  8. ZR2019暑期集训游记
  9. C/C++语言100题练习计划 75——自然数拆分问题(DFS算法实现)
  10. Centos安装Redis教程,详细步骤