I find the type of device using WURFL.Also i have written plugin to set the template for mobile view. Kindly look on below code.
class ZC_Controller_Plugin_Mobile extends Zend_Controller_Plugin_Abstract
{
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request) {
$bootstrap = Zend_Controller_Front::getInstance()->getParam("bootstrap");
$useragent = $bootstrap->getResource("useragent");
$device = $useragent->getDevice();
Zend_Registry::set("useragent", $useragent);
Zend_Registry::set("device", $device);
/**
* @todo change this to be Mobile
*/
//echo $device->getType() . " is the type of device";
if($device->getType() == "mobile") {
/**
* Set the layout to be mobile, here we make sure we streamline what is loaded
* so as to not load things that arent needed.
*/
Zend_Layout::getMvcInstance()->setLayout("mobile");
/**
* Here we check to see if a mobile version of the template exists. if it does then we change the view suffix
* this allows us to load the mobile view if it exists and the defgault view if it doesnt.
*/
$base = APPLICATION_PATH . "/views/scripts/";
$mobile = $base . $request->getControllerName() . "/" . $request->getActionName() . ".mobile.phtml";
if(is_readable($mobile)) {
Zend_Controller_Action_HelperBroker::getExistingHelper('ViewRenderer')->setViewSuffix('mobile.phtml');
}
}
}
}
Also i have created the two templates under application/layouts/scripts/
1.layout.phtml(Desktop view)
2.mobile.phtml(Mobile view)
When i run index page,I have the view based on type of device.Now file structure is like
application/view/scripts/index/
1.index.phtml
2.index.mobile.phtml
so far so good,Now I want to separate the view path based on type of device. so that i will have path something like
application/view/scripts/index/index.phtml (Desktop view)
application/mobile/view/scripts/index/index.phtml (Mobile view)
This will be better when developing site based on view.
Kindly advice on this.
You can use
Zend_Action_Helper_ViewRenderer::setViewBasePathSpec()API documentation