Zend Framework: How do I utilize MVC for our mobile website
Ok so i have our online ordering going, its a module that i have called 'olo'. What i need now is to build a mobile version our website, totally different layout and design.
Now, how do i utilize the power of MVC, that had me sold once i started?
I want to use all the different controller classes that i have allready created in the OLO module.
Right now i have started the development of our mobile website, it's placed as another module called 'mobile'. It's build with jQuery Mobile, and i allready have quite a bit done; info-pages, contact form, etc.
All mobile devices are currently redirected to domain.tld/m
with .htacces mobile dectection. This is done to support full-website view if linked to from mobile version.开发者_运维知识库
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!
Personally, I'd use front controller plugin. Doing this inside bootstrap is a little too early step in a process for my concern.
Write a plugin that hooks preDispatch() and uses Zend_Http_UserAgent to find if application is being accessed via mobile device. Then you can set view script path to another directory. For example, let's say default is your current view directory, mobile is your new view directory. You just clone the structure and modify files and it should do the trick :)
application/
modules/
olo/
controllers/
modules/
views/
scripts/
default/
mobile/
Like ArtWorkAD said you can use in Zend Framework 1.11 the wurfl adapter that allow you to detect user agent and switch the layout but that mean each of you view need to be "universal". I never so "universal" view so far.
What you can use is the ContextSwitch of the View http://framework.zend.com/manual/en/zend.controller.actionhelpers.html#zend.controller.actionhelpers.contextswitch
It lets you create different context, it is normally use to create a csv/xml file. Let say you have a controller called Index with an action called FooAction(), I assume you already have a view scripts/index/foo.phtml
You can create a context called "mobile", which will allow you to create a view for that context like that scripts/index/foo.mobile.phtml . It's like changing layout but for a view and with the previous wurfl adapter you could change the layout an automatically switch the context.
精彩评论