登录  /  注册
首页 > php教程 > php手册 > 正文

让ThinkPHP5支持模板主题(参照ThinkPHP3.2)

php中文网
发布: 2016-10-17 09:12:07
原创
2057人浏览过

该主题支持参考ThinkPHP3.2,因很多网友呼吁,官方仍未推出支持模板主题的更新,我自己修改代码,完美支持主题
该主题支持参考ThinkPHP3.2,因很多网友呼吁,官方仍未推出支持模板主题的更新,我自己修改代码,完美支持主题

请参考tpadmin文档http://www.kancloud.cn/yuan1994/tpadmin/220597
tpadmin完美支持主题设置与切换,github仓库:https://github.com/yuan1994/tpadmin/
在线体验:http://tpadmin.demo.tianpian.net.cn 帐号:admin,密码:123456
原文地址:http://www.thinkphp.cn/code/2411.html

使用方法
在控制器里模板输出时加上theme方法://继承\think\Controller控制器时<br> return $this-&gt;theme('blue')-&gt;fetch(); <br> //或者<br> $this-&gt;theme('blue')-&gt;display();  <br><br> //没有继承\think\Controller控制器时<br> $view = \think\View();<br> return $view-&gt;theme('blue')-&gt;fetch();<br> //或者<br> $view-&gt;theme('blue')-&gt;display();  <br><br> //全局设置默认模板主题<br> //在config.php配置文件里加上<br> 'template'  =&gt; [<br>     //默认主题<br>     'default_theme' =&gt; 'blue'<br> ],主题为空时表示不使用主题,不使用主题时view模板文件路径和以前一样,例如AdminGroup的模板文件在view/admin_group/,使用blue主题时,模板文件在view/blue/admin_group/,使用red主题时,模板文件在view/red/admin_group/*
官方代码修改
thinkphp/library/think/Controller.php 第147行:    /**<br>      * 设置模板主题<br>      * tianpian <tianpian0805><br>      * @access protected<br>      * @param string $theme<br>      * @return $this<br>      */<br>     protected function theme($theme = ''){<br>         $this-&gt;view-&gt;theme($theme);<br>         return $this;<br>     }</tianpian0805>thinkphp/library/think/View.php 第171行:    /**<br>      * 设置模板主题<br>      * tianpian <tianpian0805><br>      * @access public<br>      * @param string $theme 主题名称<br>      * @return $this<br>      */<br>     public function theme($theme = ''){<br>         $this-&gt;config('default_theme',$theme);<br>         return $this;<br>     }</tianpian0805>thinkphp/library/think/view/driver/Think.php 第35行和第131行:(如果使用其他模板引擎驱动,请参照该文件修改)//第35行<br> // 模板主题 tianpian <tianpian0805><br> 'default_theme' =&gt; '',<br><br> //第131行:<br> //模板主题 tianpian <tianpian0805><br> if ($this-&gt;config['default_theme']){<br>     $template = $this-&gt;config['default_theme'] . DS . $template;<br> }</tianpian0805></tianpian0805>注意
文件修改可能会导致错位,请使用tpadmin管理后台提供的源码

智能AI问答
PHP中文网智能助手能迅速回答你的编程问题,提供实时的代码和解决方案,帮助你解决各种难题。不仅如此,它还能提供编程资源和学习指导,帮助你快速提升编程技能。无论你是初学者还是专业人士,AI智能助手都能成为你的可靠助手,助力你在编程领域取得更大的成就。
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
关于CSS思维导图的课件在哪? 课件
凡人来自于2024-04-16 10:10:18
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号