PHP建站技术分享-从入门到精通PHP建站技术分享-从入门到精通PHP建站技术分享-从入门到精通

QQ:420220301 微信/手机:150-3210-7690
当前位置:首页 > CMS教程 > Fastadmin

关于cms插件实现手机和pc分离的方法

管理员 2024-12-14
Fastadmin
7

因为本人不喜欢自适应,虽然方便但是用户体验不是太完善。所以我主张把PC和手机端分离就做了一个简单的实现方法,如下修改cms插件目录下的config文件

<?phpreturn array (  0 =>   array (    'name' => 'sitename',    'title' => '站点名称',    'type' => 'string',    'content' =>     array (    ),    'value' => '你的站点',    'rule' => 'required',    'msg' => '',    'tip' => '',    'ok' => '',    'extend' => '',  ),  1 =>   array (    'name' => 'theme',    'title' => '电脑皮肤',    'type' => 'string',    'content' =>     array (    ),    'value' => 'default',    'rule' => 'required',    'msg' => '',    'tip' => '',    'ok' => '',    'extend' => '',  ),  2 =>   array (    'name' => 'mobile',    'title' => '手机端',    'type' => 'string',    'content' =>     array (    ),    'value' => 'mobile',    'rule' => 'required',    'msg' => '',    'tip' => '',    'ok' => '',    'extend' => '',  ),  3 =>   array (    'name' => 'qrcode',    'title' => '公众号二维码',    'type' => 'image',    'content' =>     array (    ),    'value' => '/assets/addons/cms/img/qrcode.png',    'rule' => '',    'msg' => '',    'tip' => '',    'ok' => '',    'extend' => '',  ),  4 =>   array (    'name' => 'default_archives_img',    'title' => '文档默认图片',    'type' => 'image',    'content' =>     array (    ),    'value' => '/assets/addons/cms/img/noimage.jpg',    'rule' => '',    'msg' => '',    'tip' => '',    'ok' => '',    'extend' => '',  ),  5 =>   array (    'name' => 'default_channel_img',    'title' => '栏目默认图片',    'type' => 'image',    'content' =>     array (    ),    'value' => '/assets/addons/cms/img/noimage.jpg',    'rule' => '',    'msg' => '',    'tip' => '',    'ok' => '',    'extend' => '',  ),  6 =>   array (    'name' => 'default_block_img',    'title' => '区块默认图片',    'type' => 'image',    'content' =>     array (    ),    'value' => '/assets/addons/cms/img/noimage.jpg',    'rule' => '',    'msg' => '',    'tip' => '',    'ok' => '',    'extend' => '',  ),  7 =>   array (    'name' => 'default_page_img',    'title' => '单页默认图片',    'type' => 'image',    'content' =>     array (    ),    'value' => '/assets/addons/cms/img/noimage.jpg',    'rule' => '',    'msg' => '',    'tip' => '',    'ok' => '',    'extend' => '',  ),  8 =>   array (    'name' => 'domain',    'title' => '绑定二级域名前缀',    'type' => 'string',    'content' =>     array (    ),    'value' => '',    'rule' => '',    'msg' => '',    'tip' => '',    'ok' => '',    'extend' => '',  ),  9 =>   array (    'name' => 'wapopen',    'title' => '手机端是否开启',    'type' => 'radio',    'content' =>     array (      1 => '开启',      0 => '不开启',    ),    'value' => '1',    'rule' => '',    'msg' => '',    'tip' => '',    'ok' => '',    'extend' => '',  ),  10 =>   array (    'name' => 'rewrite',    'title' => '伪静态',    'type' => 'array',    'content' =>     array (    ),    'value' =>     array (      'index/index' => '/$',      'channel/index' => '/[:diyname]$',      'tags/index' => '/t/[:name]$',      'archives/index' => '/a/[:diyname]',      'page/index' => '/p/[:diyname]',      'search/index' => '/s',      'wxapp.index/index' => '/wxapp',    ),    'rule' => 'required',    'msg' => '',    'tip' => '',    'ok' => '',    'extend' => '',  ),  11 =>   array (    'name' => 'wxappid',    'title' => '小程序AppID',    'type' => 'string',    'content' =>     array (    ),    'value' => 'appid',    'rule' => 'required',    'msg' => '',    'tip' => '',    'ok' => '',    'extend' => '',  ),  12 =>   array (    'name' => 'wxappsecret',    'title' => '小程序AppSecret',    'type' => 'string',    'content' =>     array (    ),    'value' => 'appsecret',    'rule' => 'required',    'msg' => '',    'tip' => '',    'ok' => '',    'extend' => '',  ),);

然后再cms插件下的控制器中添加了一个最low的if语句如下

      parent::__construct();        $config = get_addon_config('cms');        $waparray=array('android','iphone','ipad','mobile');        foreach($waparray as $thisphone) {            if(stripos($_SERVER['HTTP_USER_AGENT'],$thisphone)===false) {                $mobile = false;}else {                $mobile = true;         }        }        if($config['wapopen']==1 && $mobile == 1){        $this->view->engine->config('view_path', $this->view->engine->config('view_path') . $config['mobile'] . DS);        }else{        $this->view->engine->config('view_path', $this->view->engine->config('view_path') . $config['theme'] . DS);            }

希望以上内容对你有所帮助!如果还有其他问题,请随时提问。 各类知识收集 拥有多年CMS企业建站经验,对 iCMS, Fastadmin, ClassCMS, LeCMS, PbootCMS, PHPCMS, 易优CMS, YzmCMS, 讯睿CMS, 极致CMS, Wordpress, HkCMS, YznCMS, WellCMS, ThinkCMF, 等各类cms的相互转化,程序开发,网站制作,bug修复,程序杀毒,插件定制都可以提供最佳解决方案。

相关推荐

扫码关注

qrcode

QQ交谈

回顶部