1.创建2个视图文件 ![](https://box.kancloud.cn/9c880d46df57dea0f1279239fc0ee880_427x227.png) 2.定义1个函数(用于判断是否是手机) ``` //这个函数放公共函数中(common.php) function isMobile(){ if (isset ($_SERVER['HTTP_X_WAP_PROFILE'])){ return true; } if (isset ($_SERVER['HTTP_VIA'])){ return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false; } if (isset ($_SERVER['HTTP_USER_AGENT'])){ $clientkeywords = array ('nokia', 'sony', 'ericsson', 'mot', 'samsung', 'htc', 'sgh', 'lg', 'sharp', 'sie-', 'philips', 'panasonic', 'alcatel', 'lenovo', 'iphone', 'ipod', 'blackberry', 'meizu', 'android', 'netfront', 'symbian', 'ucweb', 'windowsce', 'palm', 'operamini', 'operamobi', 'openwave', 'nexusone', 'cldc', 'midp', 'wap', 'mobile' ); if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))){ return true; } } if (isset ($_SERVER['HTTP_ACCEPT'])){ if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))){ return true; } } return false; } ``` 3.入口文件,增加判断手机函数(index.php文件) ``` //判断是PC还是移动 function ispcyd(){ $agent = strtolower($_SERVER['HTTP_USER_AGENT']); $is_pc = (strpos($agent, 'windows nt')) ? true : false; $is_mac = (strpos($agent, 'mac os')) ? true : false; $is_iphone = (strpos($agent, 'iphone')) ? true : false; $is_android = (strpos($agent, 'android')) ? true : false; $is_ipad = (strpos($agent, 'ipad')) ? true : false; if($is_pc){ return false; } if($is_mac){ return true; } if($is_iphone){ return true; } if($is_android){ return true; } if($is_ipad){ return true; } } ``` 4.定义视图VIEW文件地址(常量) ``` if (ispcyd()) { //如果手机端 define('VIEW_PATH_PCYD', __DIR__ . '/../application/admin/view/mobile/'); } else { //默认PC端 define('VIEW_PATH_PCYD', __DIR__ . '/../application/admin/view/default/'); } ``` 5.定义视图VIEW文件地址(常量) ``` // 模板路径 'view_path' => VIEW_PATH_PCYD, ``` ![](https://box.kancloud.cn/d7d303aa91b713e3b7a8c30b3165cb5c_668x360.png) 6.收尾工作(不是必须的,看情况使用!) ![](https://box.kancloud.cn/6ab5f06ff48f1a62e869b1704b4f7528_680x417.png)