thinkphp5 实现多主题 和 自动识别终端调用不同主题

浏览:1406 发布日期:2017/12/02 分类:功能实现 关键字: thinkphp5 tp5 多主题 自动识别
通过重写view或fetch的方式实现多主题 自动识别终端的功能
还需要进一步完善,待大家一起做吧,欢迎交流学习QQ761762757
// 重写模板调用方法
protected function fetch($template = '', $vars = [], $replace = [], $config = [])
{
$term_type = \think\Request::instance()->isMobile() ? 'moblie' : 'pc';
$theme = \think\Config::get('template.theme')?:'default';
$module = \think\Request::instance()->module();
$controller = \think\Request::instance()->controller();
$action = \think\Request::instance()->action();
// 精确的做法是对$template进行判断,看看是否跨控制器,是否跨模块,是否是多层级控制器
if(!$template)
{
$template = $theme.'\\'.$term_type.'\\'.$module.'\\'.$controller.'\\'.$action;
}
elseif(!substr_count($template,'/')){
$template = $theme.'\\'.$term_type.'\\'.$module.'\\'.$controller.'\\'.$template;
}
elseif(substr_count($template,'/')==1){
$template = $theme.'\\'.$term_type.'\\'.$module.'\\'.$template;
}
else{
$template = $template;
}
return $this->view->fetch( $template , $vars, $replace, $config);
}
评论( 相关
后面还有条评论,点击查看>>