I cant find a solution to my problem anywhere, be it on SO or within the actual zend documentation.
Basically i have this setup:
I've created a plugin which using Zend_Http_UserAgent and WURFL to detect if the user is currently using a mobile. This is done in the predispatch. This works fine
I now want to change the view scripts directory if the user is using a mobile.
Ideally in a perfect world i'd like to try and load the mobile version of the view, if it exists, if not then load the default view. But if i can get 2 working at the least then i'll be happy.
I am more than stumped on how i do this. I've seen i could use:
$view = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view; $view->setBasePath(APPLICATION_PATH . '/mobile_views/');
But that doesnt seem to do what i expect, plus this happens in postDispatch when i think this sort of thing should happen in preDispatch?
Here is my current plugin:
<?php
class SQ_Plugins_Mobile extends Zend_Controller_Plugin_Abstract {
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $flag) {
$bootstrap = Zend_Controller_Front::getInstance()->getParam("bootstrap");
$useragent = $bootstrap->getResource("useragent");
$device = $useragent->getDevice();
Zend_Registry::set("useragent", $useragent);
Zend_Registry::set("device", $device);
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 i wish to change the view path to be APPLICATION_PATH . "/mobile_views/"
* @todo Change the view script path
*/
}
}
public function postDispatch(Zend_Controller_Request_Abstract $request) {
/**
* Maybe i have to change the view script path here?
* @todo change the viewscript path if we're using a mobile
*/
// Get the current view
$view = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view;
$view->setBasePath(APPLICATION_PATH . '/mobile_views/');
echo "kl;kl;kjhkl;jhlkjhjklhkl;h k;hi";
}
}