Home  >  Article  >  php教程  >  Let ThinkPHP5 support template themes (refer to ThinkPHP3.2)

Let ThinkPHP5 support template themes (refer to ThinkPHP3.2)

WBOY
WBOYOriginal
2016-10-17 09:12:072216browse

This theme supports the reference ThinkPHP3.2. Due to the appeal of many netizens, the official has not released the update to support the template theme. I modified the code myself to perfectly support the theme.
The theme supports the reference ThinkPHP3.2. Due to the appeal of many netizens, the official has not yet launched the support. For the update of the template theme, I modified the code myself to perfectly support the theme

Please refer to the tpadmin document http://www.kancloud.cn/yuan1994/tpadmin/220597
tpadmin perfectly supports theme setting and switching, github repository: https://github.com/yuan1994/tpadmin/
Online experience: http://tpadmin.demo.tianpian.net.cn Account: admin, password: 123456
Original address: http://www.thinkphp.cn/code/2411.html

How to use
Add the theme method when outputting the template in the controller: //When inheriting the thinkController controller<br> return $this->theme('blue')->fetch(); <br> //or <br> $this->theme('blue')->display(); <br> <br> //When the thinkController controller is not inherited<br> $view = thinkView();<br> return $view->theme('blue')->fetch();<br> //or <br> $view->theme('blue')->display(); <br> <br> //Set the default template theme globally<br> //Add <br> to the config.php configuration file 'template' => [<br> //Default theme<br> 'default_theme' => 'blue'<br> ],When the theme is empty, it means that the theme is not used. When the theme is not used, the view template file path is the same as before. For example, the template file of AdminGroup is in view/admin_group/. When using the blue theme, the template file is in view/blue/admin_group/. When using the red theme, the template file is in view/red/admin_group/*
Official code modification
thinkphp/library/think/Controller.php line 147: /**<br> * *Set template theme<br> * tianpian <tianpian0805@gmail.com><br> * * @access protected<br> * * @param string $theme<br> * * @return $this<br> ​​*/<br> protected function theme($theme = ''){<br>           $this->view->theme($theme);<br> Return $ this; <br> }thinkphp/library/think/View.php line 171:  /**<br> * *Set template theme<br> * tianpian <tianpian0805@gmail.com><br> * * @access public<br> * @param string $theme theme name<br> * * @return $this<br> ​​*/<br> Public function theme($theme = ''){<br>           $this->config('default_theme',$theme);<br> Return $ this; <br> } }thinkphp/library/think/view/driver/Think.php Lines 35 and 131: (If you use other template engine drivers, please refer to this file for modification) //Line 35<br> // Template theme tianpian <tianpian0805@gmail.com><br> 'default_theme' => '',<br> <br> //Line 131: <br> //Template theme tianpian <tianpian0805@gmail.com><br> if ($this->config['default_theme']){<br> $template = $this->config['default_theme'] . DS . $template;<br> }Attention
File modification may cause misalignment, please use the source code provided by tpadmin management background

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn