万维当云伯乐 CDN华纳云
ThinkPHP2024-06-271,098 阅读

thinkphp实现手机端与电脑端双模板的方法与详细教程

本文摘要[caption id="attachment_2589" align="aligncenter" width="800"] thinkphp[/caption] thinkphp8 实现手机端与电脑端双模板的方法 首先加载第三方判断客户端UA类库 类库地址 http://mobiledetect.net/ compo
丽萨主机
AD:
【广告招商】文章正文文字广告位开放合作
thinkphp thinkphp thinkphp8 实现手机端与电脑端双模板的方法 首先加载第三方判断客户端UA类库  类库地址 http://mobiledetect.net/
composer require mobiledetect/mobiledetectlib
编辑你的项目目录基础类文件Base 引入下载的类库
use Detection\MobileDetect;
  在控制器渲染模板的时候直接判断即可
$MobileDetect = new MobileDetect;
if ($MobileDetect->isMobile()) {
    $this->view('mobile');
} else {
  $this->view('pc');
}
 
广告招商文章内容详情页下 · 优质席位开放中合作咨询