//layout.html {include file="public/header" /} {__CONTENT__} {include file="public/footer" /}
//public/header.html <!doctype html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> *{ margin: 0px; padding: 0px; } .header{ background: #000000; height: 60px; width: 100%; } .header ul{ width: 80%; height:60px; line-height: 60px; margin:0px auto; text-align: center; } .header li{ float: left; margin-left: 15px; width: 10%; list-style: none; } .header li a{ text-decoration: none; color: #EEEEEE; } </style> </head> <body> <div> <div menu> <ul> <li><a href="">首页</a></li> <li><a href="">视频教程</a></li> <li><a href="">社区问答</a></li> <li><a href="">技术文章</a></li> <li><a href="">编程词典</a></li> <li><a href="">资源下载</a></li> <li><a href="">菜鸟学堂</a></li> </ul> </div> </div>
<style> .footer{ width:100%; height: 150px; background: #232323; } .footer_content{ text-align: center; color: #EEEEEE; height: 150px; line-height: 150px; font-size: 12px; } </style> <div class="footer"> <div class="footer_content"> Copyright 2014-2019 http://www.php.cn/ All Rights Reserved | 皖B2-20150071-9 皖公网安备 34010402701654号 免责申明赞助与捐赠</div> </div> </body> </html>
//控制器index <?php namespace app\index\controller; use think\Controller; class Index extends Controller { public function index() { return 'OK'; } public function demo1() { $name = 'php 中文网'; $this->assign('name',$name); $this->assign('name1','输出name1'); $this->assign('name2','输出name2'); $this->assign('name3','输出name3'); $this->view->date='对象赋值date'; return $this->fetch(); } public function demo2() { $this->view->name='php 中文网'; $this->view->data='海量资源'; return $this->view->filter(function ($content){ return str_replace('php 中文网','欢迎来到 php中文网',$content); })->fetch(); } public function demo4() { return $this->view->engine->layout(true)->fetch('index/demo4'); } public function demo5() { return $this->view->engine->layout(true)->fetch('index/demo5'); } public function demo6() { return $this->view->engine->layout(true)->fetch('index/demo6'); } }
//正文部分html代码 <style> .content{ width: 100%; height: 600px; background: #999999; } .content_up{ width: 80%; height: 600px; margin: 0px auto; background: #f8cbcb; } </style> <div class="content"> <div class="content_up"> 网页demo4内容部分 </div> </div>
<div> <style> .content{ width: 100%; height: 600px; background: #999999; } .content_up{ width: 80%; height: 600px; margin: 0px auto; background: #f8cbcb; } </style> <div class="content"> <div class="content_up"> 网页demo5内容部分 </div> </div> </div>
<div> <style> .content{ width: 100%; height: 600px; background: #999999; } .content_up{ width: 80%; height: 600px; margin: 0px auto; background: #f8cbcb; } </style> <div class="content"> <div class="content_up"> 网页demo6内容部分 </div> </div> </div>
经过本章节学习学会了在框架中对视图渲染,模板布局等知识。框架开发技术又进一步提升