开发者

How to handle mobile devices in Zend Framework?

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开发者_如何学Go. 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


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!


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

}


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜