最新消息:XAMPP默认安装之后是很不安全的,我们只需要点击左方菜单的 "安全"选项,按照向导操作即可完成安全设置。

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

XAMPP教程 admin 813浏览 0评论

总结流程:

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

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

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

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

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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?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语句如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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);   
       }

转载请注明:XAMPP中文组官网 » fastadmincms插件实现手机和pc分离方法代码

您必须 登录 才能发表评论!