豆豆
|
|
【实现PC端访问PC模板 [www.xx.com]、手机端访问WAP模板 [m.xx.com]】
twcms添加手机端模板: 修改程序代码【实现PC端访问PC模板 [www.xx.com]、手机端访问WAP模板 [m.xx.com]】
详细方法: 1、打开\twcms\model\runtime_model.class.php; 2、找到public function xget($key = 'cfg') { 大概在36行左右 3、将下面新函数代码覆盖掉原来的- // 读取
- public function xget($key = 'cfg') {
- if(!isset($this->data[$key])) {
- $this->data[$key] = $this->get($key);
- if($key == 'cfg' && empty($this->data[$key])) {
- $cfg = (array)$this->kv->get('cfg');
- empty($cfg['theme']) && $cfg['theme'] = 'default';
- $cfg['tpl'] = $cfg['webdir'].(defined('F_APP_NAME') ? F_APP_NAME : APP_NAME).'/view/'.$cfg['theme'].'/';
- $cfg['webroot'] = '//'.$cfg['webdomain'];
- $cfg['weburl'] = '//'.$cfg['webdomain'].$cfg['webdir'];
- $cfg['waproot'] = '//'.$cfg['wapdomain'];
- $cfg['wapurl'] = '//'.$cfg['wapdomain'].$cfg['webdir'];
- $table_arr = $this->models->get_table_arr();
- $cfg['table_arr'] = $table_arr;
- $mod_name = $this->models->get_name();
- unset($mod_name[1]);
- $cfg['mod_name'] = $mod_name;
- $this->data[$key] = &$cfg;
- $this->set('cfg', $this->data[$key]);
- }
- }
-
- //需要实时判断
- if($key == 'cfg' && is_mobile()){
- $cfg = (array)$this->kv->get('cfg');
-
- $this->data['cfg']['theme'] = 'mobile_theme';
- $this->data['cfg']['tpl'] = $this->data['cfg']['webdir'].(defined('F_APP_NAME') ? F_APP_NAME : APP_NAME).'/view/mobile_theme/';
-
- $cfg['webroot'] = '//'.$cfg['wapdomain'];
- $cfg['weburl'] = '//'.$cfg['wapdomain'].$cfg['webdir'];
-
- if($_SERVER['HTTP_HOST']==$cfg['webdomain']){
- if(empty($_SERVER['QUERY_STRING'])){
- Header("Location: $cfg[weburl]");
- }else{
- $urlcs = str_replace('rewrite=','',$_SERVER['QUERY_STRING']);
- $url = '//'.$cfg['wapdomain'].$cfg['webdir'].$urlcs;
- Header("Location: $url");
- }
- }
- }
- return $this->data[$key];
- }
复制代码 其中$cfg['wapdomain']就是你自定义的wap域名,可以写死,可以去自己去后台管理 代码里添加一个新字段,当然这个比较灵活。
修改方法参考: http://www.twcms.cc/thread-2-1-1.html http://www.twcms.cc/thread-14-1-1.html
|
|
|
|
发帖时间:2018-5-14 |
查看数:0 |
回复数:6
|