fastadmincms插件实现手机和pc分离的方法

  • 内容
  • 评论
  • 相关

总结流程:

1,更改配置文件,管理移动端开启和目录

2,base文件更改,增加移动端判断

3,建立移动端模板目录,可以复制pc的改改。*(找对目录)

------------------------------------------喜欢就发个小红包哦----------------------------------------

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

view目录下建立mobile目录存放移动模板

<?php

return 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插件下的控制器(
cms的基类控制器Base.php )中添加了一个最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);    
        }


产品经理都很寂寞!
扫一扫来撩!!!
  微信公众号码:kelebl
  QQ群:497315816