Android程序员学PHP开发(36)-ThinkPHP5.0(8)前台引入模板分离-phpStudy+Sublime

转载请注明出处: http://blog.csdn.net/iwanghang/article/details/60868756
觉得博文有用,请点赞,请评论,请关注,谢谢!~

上一篇博文,我们练习了一下 站点域名管理 和 自动生成,在这个基础上,我们来练习一下 童攀老师的博客搭建。

我在群里下载了一个压缩包,我们就以这个压缩包为基础,进行练习:

thinkphp5第一季【你我网】前后台模板:http://download.csdn.net/detail/iwanghang/9773861

关于thinkphp的MVC结构,这里不做介绍,如果不知道什么MVC请务必先去了解一下,再继续往下看:


1、controller 控制器:

/application/index/controller/Index.php

<?php
/**
 * 主页控制器
 */
namespace app\index\controller;
use think\Controller;
class Index extends Controller
{
    public function index()
    {
        return $this->fetch();
    }
}

/application/index/controller/Article.php

<?php
/**
 * 文章页面控制器
 */
namespace app\index\controller;
use think\Controller;
class Article extends Controller
{
    public function index()
    {
        return $this->fetch('article');
    }
}
/application/index/controller/Guest.php

<?php
/**
 * 留言板控制器
 */
namespace app\index\controller;
use think\Controller;
class Guest extends Controller
{
    public function index()
    {
        return $this->fetch('guestbook');
    }
}
/application/index/controller/Lst.php (这里需要注意,不能使用List,List是php保留变量)

<?php
/**
 * 列表页控制器
 */
namespace app\index\controller;
use think\Controller;
class Lst extends Controller
{
    public function index()
    {
        return $this->fetch('list');
    }
}
/application/index/controller/Search.php

<?php
/**
 * 搜索页控制器
 */
namespace app\index\controller;
use think\Controller;
class Search extends Controller
{
    public function index()
    {
        return $this->fetch('search');
    }
}

2、view 视图

这里就不上代码了,就是上面资源里面的文件,这里给出来一下路径,让大家看一下。

/application/index/view/Index/index.html

/application/index/view/Article/article.html

/application/index/view/Guest/guestbook.html

/application/index/view/Lst/list.html

/application/index/view/Search/search.html

还有2个文件,后面分离 网站头部和尾部 需要用到

/application/index/view/Public/header.html

/application/index/view/Public/footer.html

3、拷贝样式和资源(下面这2个文件夹都在压缩包里)

/public/static/index/images

/public/static/index/style

4、输出替换:http://www.kancloud.cn/manual/thinkphp5/118120


/application/config.php 这里是配置文件,在最后加上这段代码:

    // 如果需要全局替换的话,可以直接在配置文件中添加:
'view_replace_str'  =>  [
    '__PUBLIC__'=>'/public/',
    '__ROOT__' => '/',
]

5、把view里面的html的路径替换为全局路径

例子:

<link rel="stylesheet" rev="stylesheet" href="__PUBLIC__/static/index/style/style.css" type="text/css" media="screen" />
<img src="__PUBLIC__/static/index/images/2016021074509417.jpg" title="你我网" alt="你我网"/>

6、进行头部和尾部的分离

从view中提取,并修改下面2个文件:

/application/index/view/Public/header.html

		<div id="divTop">
			<h1 id="BlogTitle"><a href="http://www.iwanghang.com/"><img src="__PUBLIC__/static/index/images/LOGO.gif" alt="你我网" onMouseover="shake(this,'onmouseout')" /></a></h1>
			<!-- <h3 id="BlogSubTitle">www.iwanghang.com</h3> -->
		</div>
		<div id="divNavBar">
<ul>
<li><a href="http://www.iwanghang.com/">首页</a></li><li><a href="http://www.iwanghang.com/catalog.asp?cate=2" title="感悟生活点滴">大生活</a></li><li><a href="http://www.iwanghang.com/catalog.asp?cate=3" title="光与影的艺术">光影斑斓</a></li><li><a href="http://www.iwanghang.com/catalog.asp?cate=4" title="一切有为法,如梦幻泡影,如露亦如电,应作如是观。">如是观</a></li><li><a href="http://www.iwanghang.com/t/" target="_blank" title="还是以前的圈圈微博!">圈圈说</a></li><li><a href="http://www.iwanghang.com/guestbook.html" title="沟通从这里开始">留言本</a></li>
</ul>
		</div>
/application/index/view/Public/footer.html

		<div id="divTop">
			<h1 id="BlogTitle"><a href="http://www.iwanghang.com/"><img src="__PUBLIC__/static/index/images/LOGO.gif" alt="你我网" onMouseover="shake(this,'onmouseout')" /></a></h1>
			<!-- <h3 id="BlogSubTitle">www.iwanghang.com</h3> -->
		</div>
		<div id="divNavBar">
<ul>
<li><a href="http://www.iwanghang.com/">首页</a></li><li><a href="http://www.iwanghang.com/catalog.asp?cate=2" title="感悟生活点滴">大生活</a></li><li><a href="http://www.iwanghang.com/catalog.asp?cate=3" title="光与影的艺术">光影斑斓</a></li><li><a href="http://www.iwanghang.com/catalog.asp?cate=4" title="一切有为法,如梦幻泡影,如露亦如电,应作如是观。">如是观</a></li><li><a href="http://www.iwanghang.com/t/" target="_blank" title="还是以前的圈圈微博!">圈圈说</a></li><li><a href="http://www.iwanghang.com/guestbook.html" title="沟通从这里开始">留言本</a></li>
</ul>
		</div>

7、分离头部和尾部

如图:

头部:


尾部:




8、遗留问题:

我们想要的效果,访问下面的连接打开留言页:

http://www.iwanghang.com/guest

暂时只有访问下面的连接,才可以访问留言页,我们后续会来解决这个问题:

http://www.iwanghang.com/index/guest




转载请注明出处: http://blog.csdn.net/iwanghang/article/details/60868756


欢迎移动开发爱好者交流
沈阳或周边城市公司有意开发Android,请与我联系
联系方式

微信:iwanghang
QQ:413711276
邮箱:iwanghang@qq.com



觉得博文有用,请点赞,请评论,请关注,谢谢!~

〖课程目录〗 01.课程简介.mp4 02.后台界面初步引入.mp4 03.四种引入界面方式详解及其他界面引入.mp4 04.分离后台的公共部分并引入.mp4 05.前台模板文件分离模板引入完成】.mp4 06.前台界面引入.mp4 07.管理员的添加.mp4 08.添加管理员的多种方法.mp4 09.管理员数据的各种查询方法.mp4 10.其他添加数据的方法补充.mp4 11.分页详解.mp4 12.控制器层的修改.mp4 13.模型层的修改与删除.mp4 14.管理员登录的三种情况.mp4 15.管理员杂项.mp4 16.无限级分类:数据表及界面.mp4 17.无限级分类:栏目添加功能.mp4 18.无限级分类:无限级显示.mp4 19.无限级分类:无限极删除.mp4 20.无限级分类:栏目的修改.mp4 21.无限级分类:栏目排序.mp4 22.文章数据表及界面处理.mp4 23.文章的添加及控制器层图片上传.mp4 24.通过钩子函数(事件函数)在模型层上传图片(文件).mp4 25.文章列表及联表查询.mp4 26.文章修改.mp4 27.问题解决及文章删除.mp4 28.杂项处理.mp4 29.友情链接1.mp4 30.链接的修改与删除.mp4 31.数据验证详解.mp4 32.其他数据验证.mp4 33.配置表创建及模板处理.mp4 34.配置的添加及删除.mp4 35.配置修改.mp4 36.显示配置项的5种类型.mp4 37.配置项显示及修改提交.mp4 38.配置的选定项.mp4 39.配置杂项.mp4 40.后台验证码.mp4 41.栏目内容补充.mp4 42.Auth权限认证1:基本表结构创建.mp4 43.Auth权限认证2:用户组的添加与显示.mp4 44.Auth权限认证3:用户组的删除与修改.mp4 45.Auth权限认证4:添加权限规则.mp4 46.Auth权限认证5:权限的无限级显示.mp4 47.Auth权限认证6:无限级权限的修改与删除.mp4 48.Auth权限认证7:用户组显示权限列表.mp4 49.Auth权限认证8:权限的js选择控制.mp4 50.Auth权限认证9:为用户组分配权限.mp4 51.Auth权限认证10:为管理员分配用户组的新增与修改.mp4 52.Auth权限认证11:完成权限认证功能.mp4 tp5第二季完整资源包.rar
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值