您的位置:首页 > 编程语言 > PHP开发

ThinkPHP 3.1.2 模板的使用技巧

2016-04-21 15:23 525 查看
本节课大纲:
一、模板包含
<include file="完整模板文件名" />
<include file="./Tpl/default/Public/header.html" />
<include file="read" />
<include file="Public:header" />
<include file="blue:User:read" />
<include file="$tplName" />
<include file="header" title="ThinkPHP框架"keywords="开源WEB开发框架"/>
在模板中变量用[变量]接受
<include file='file1,file2' />
二、模板渲染
1、自动开启模板渲染 设置配置文件
'LAYOUT_ON'=>true,//开启模板渲染
准备一个模板渲染页面,在页面中使用{__CONTENT__}接受具体模板页面的内容
如果在摸一个具体模板中不希望使用渲染模板,可以在页首添加{__NOCONTENT__}
2、不开启自动模板渲染可以在每一个具体页面的页首添加
<layout name='layout'/>
三、模板的继承

//
<p>这里是首页</p>
<a href='__URL__/next'>跳转到下一页</a>

点击超链接,去查找next方法

非法操作:next
错误位置
FILE: C:\wamp\www\thinkphp2\ThinkPHP\Lib\Core\Action.class.php  LINE: 231

在框架之中,找一个具体页面的时候,总是跳转到一个方法,总是有控制器里的方法,为我们输出页面

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<!--<link rel='stylesheet' type='text/css' href='__PUBLIC__/Css/test.css'/>-->
<!--<script src='__PUBLIC__/Js/test.js'></script>-->
<!--<import type='css' File='Css.test'/>

<import type='js' File='Js.test'/>-->
<title>Document</title>
</head>
<body>
<p>这里是首页</p>
<a href='__URL__/next'>跳转到下一页</a>

</body>
</html>

超连接查找next 方法

public function next(){
$this->display();
}

netx 方法对应的页面

//thinkphp 公共的模板文件

$ pwd
/cygdrive/c/wamp/www/thinkphp2/Home/Tpl/Public

Administrator@QCEE61NZ66FEX2D /cygdrive/c/wamp/www/thinkphp2/Home/Tpl/Public
$ ls
head.html  header.html

<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus?">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">

<title>Document</title>
<load file="__PUBLIC__/Css/test.css"/>
</head>
</html>

引入header.html模板文件
<!doctype html>
<include file="Public:header"/>
<body>
<p>这里是首页</p>
<p>"__APP__/Public/code"<p>
<a href='__URL__/next'>跳转到下一页</a>

</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: