用thinkcmf5.1写项目的时候如何实现PC端和手机端自动切换?
1.首先找到data/config/template.php文件
复制 'cmf_admin_default_theme' => 'houtai', /houtai是后台模板文件夹名称
改为 'cmf_mobile_default_theme' => 'wap', //wap是手机站模板文件夹名称
之后在public/theme文件夹下复制pc端文件夹 更改文件夹名称为template.php文件中添加的名称 (这里我的名称是wap)
2.更改 vendor/thinkcmf/cmf/src/common.php 文件
在vendor/thinkcmf/cmf/src/common.php 文件中搜索 cmf_get_current_theme 这个函数是 “获取当前主题名”
在方法中 找到 $theme = config('template.cmf_default_theme'); 这一行代码 改为下面的判断
if(cmf_is_mobile()){
$theme = config('template.cmf_mobile_default_theme');
}else{
$theme = config('template.cmf_default_theme');
}
如下图:
这两个文件更改完成后就可以实现pc端和手机端访问的自动切换了