dplbf4340 2015-03-23 03:37
浏览 24
已采纳

用户来自opera mini时发送到另一个控制器

I have developed a website in Symfony2. I am using Suncat MobileDetectBundle to detect if a user is from mobile or PC. I have to create 3 separate versions for desktop, smartphones and for Java based phones. I have a DefaultController with following code

    public function indexAction()
    {
    $mobileDetector = $this->get('mobile_detect.mobile_detector');
    if($mobileDetector->isMobile())
    $render='AcmeUitBundle:Android:Default/';
    else
     $render='AcmeUitBundle:Default:';
    //More Code goes here
    }

When a user is from smartphone, It will render template present in 'Android/Default' folder and when he is from Computer,Templates from 'Default' folder are displayed.

Now I have another controller, 'JavaController' in which I will have code to display for Java based phones.

What I want to do is to check when a user is from a java based phone,Opera mini or ucweb, then execute JavaController and when user is from a smartphone or Desktop then execute DefaultController

  • 写回答

1条回答 默认 最新

  • dpy87530 2015-03-23 07:18
    关注

    To know if the phone is android you can use :

    extends \Mobile_Detect {}
    
    if($this->is('AndroidOS')){
    }
    

    Suncat extends the mobile_detect library which have lot of kind of checks as AndroidOS check IOS etc... so you can use that.

    Edit :

    I understand better now, you can either use this indexAction and detect if it is android with this code :

    if($mobileDetector->isMobile()){
       if(mobileDetector->is('AndroidOS')){
           return $this->forward('YourBundle:Java:index'); //this is your bundle name your controller name then your action name.
        }
        $render='AcmeUitBundle:Android:Default/';
     }
     else
         $render='AcmeUitBundle:Default:';
        //More Code goes here
        }
    

    Or use another action that will detect mobile and which OS then forward to whatever action controller you need either default one or java one

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?