How to handle mobile devices in Zend Framework?

2019-03-20 04:03发布

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

4条回答
我想做一个坏孩纸
2楼-- · 2019-03-20 04:15

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!

查看更多
Summer. ? 凉城
3楼-- · 2019-03-20 04:17

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

查看更多
聊天终结者
4楼-- · 2019-03-20 04:27

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

}

查看更多
Lonely孤独者°
5楼-- · 2019-03-20 04:31

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.

查看更多
登录 后发表回答