I can’t find a solution to my problem anywhere, whether on SO or in real zend documentation.
I basically have this setting:
I created a plugin that uses Zend_Http_UserAgent and WURFL to determine if the user is using a mobile phone. This is done in advance. It works great
Now I want to change the catalog of view scripts if the user is using mobile.
In an ideal world, I would like to try and download the mobile version of the view, if it exists, if not download the default view. But if I can get 2, I work as a minimum, I will be happy.
I'm more than dumb about how I do it. I saw that I can use:
$ view = Zend_Controller_Action_HelperBroker :: getStaticHelper ('viewRenderer') → view; $ view-> setBasePath (APPLICATION_PATH. '/ mobile_views /');
But that doesn't seem to do what I expect, plus does this happen in postDispatch when I think such a 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") {
Zend_Layout::getMvcInstance()->setLayout("mobile");
}
}
public function postDispatch(Zend_Controller_Request_Abstract $request) {
$view = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view;
$view->setBasePath(APPLICATION_PATH . '/mobile_views/');
echo "kl;kl;kjhkl;jhlkjhjklhkl;h k;hi";
}
}
source
share