学习加载模板。
1、修改:IndexController.class.php
内容:
<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
public function index(){
$this->display(); // 加载模板的函数
}
}
浏览:http://localhost/myweb/
浏览器出错,显示:模板不存在:./Application/Home/View/Index/index.html
2、生成模板文件:D:\wamp\www\MyWeb\Application\Home\View\Index\index.html
文件内容:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>ThinkPHP示例:模板</title>
<style type="text/css">
*{ padding: 0; margin: 0;font-size:16px; font-family: "微软雅黑"}
div{ padding: 3px 20px;}
body{ background: #ffb; color: #333;}
h2{font-size:36px}
a{text-decoration:none; color:#174B73; border-bottom:1px dashed gray}
a:hover{color:#F60; border-bottom:1px dashed gray}
div.result{border:1px solid #d4d4d4; background:#FFC;color:#393939; padding:8px 20px;float:auto; width:350px;margin:2px}
</style>
</head>
<body>
<div class="main">
<block name="title">提示</block>
<block name="content1"><div class="result">这里是父模板定义内容1</div></block>
<block name="content2"><div class="result">这里是父模板定义内容2</div></block>
<block name="content3"><div class="result">这里是父模板定义内容3</div></block>
<block name="content4"><div class="result">这里是父模板定义内容4</div></block>
<block name="content5"><div class="result">这里是父模板定义内容5</div></block>
<block name="content6"><div class="result">这里是父模板定义内容6</div></block>
</div>
</body>
</html>
3、再次浏览:http://localhost/myweb/