Thinkphp如何制作一个PC网站和移动端网站

相信大家用thinkphp做一个普通的PC网站应该没什么问题,thinkphp3.2模块化编程,前台模块和后台模块分开的,如何要一个PC网站和移动端网站,只需要复制一个模块就可以了

1,第一种方法,新建移动模块

Thinkphp如何制作一个PC网站和移动端网站_第1张图片

2,第二种方法,在文件里面设置

public function index()
    {
        $this->assign('isIndex',1);
        $pcmobile=is_mobile();
        if(!$pcmobile){
          $this->display("Index:index");
        }else{
           $this->display("Index:index:m");    
        }
    }

common文件判断pc和移动端代码

function is_mobile()
{
    $ua = strtolower($_SERVER['HTTP_USER_AGENT']);
    $uachar = "/(nokia|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|alcatel|lenovo|cldc|midp|mobile)/i";
    if(($ua == '' || preg_match($uachar, $ua)))
     {
        return true;
     }
}

3,制作响应网站 bootstrap

文章来自Thinkphp爱好者 http://www.96net.com.cn/

你可能感兴趣的:(Thinkphp)