How to handle mobile devices in Zend Framework?

好久不见. 提交于 2020-01-01 03:18:07

问题


I've taken over a nightmare of a project! I'm moving a very poorly written site and moving it slowly into a Zend Framework application. Unfortunately I have no time to do the remedial work to make this even bearable (maybe a model or two). I have now been told that it is soon to have mobile version of the site and the proposal has been to clone the old site and work with that. In an attempt to not work on different versions of the same crap and buy myself some time I proposed that the ZF site should handle it all.

Is it awful practice to use Zend_Http_UserAgent to detect then simply load an alternative layout and content?

I was inclined to use two modules at first but I've had a bit of trouble with ACLs in modules.

Any alternative suggestions are welcome!

Cheers


回答1:


With Zend Framework 1.11 zend introduced the wurfl adapter which is based on Zend_Http_UserAgent.

It allows you to detect mobile devices and bootstrap different layouts. There is a HOW TO on youtube that came with the zend newsletter december 2010: http://www.youtube.com/watch?v=_A8yg73tqOY

You don't have to use different modules! Just different layout files!




回答2:


if (Zend_Http_UserAgent_Mobile::match($_SERVER['HTTP_USER_AGENT'], $_SERVER)) {

}




回答3:


A good starting point would be to look at responsive design techniques with css. There are many tutorials out there just google "responsive design" and perhaps you can refactor the existing layout.




回答4:


The recommended way for Zend/Magento :

$isUsingMobile =    Zend_Http_UserAgent_Mobile::match(
                            Mage::helper('core/http')->getHttpUserAgent(),
                            $_SERVER
                        );
    if($isUsingMobile)
    {   
        //Do something 
    }
    else
    {
            //Do something
    }

It returns either true or false. Note: You must have the userAgent library inside Zend/Http



来源:https://stackoverflow.com/questions/5541171/how-to-handle-mobile-devices-in-zend-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!