In your Module.php file in the appropriate module you can do something along these lines:

public function onBootstrap(MvcEvent $event)
{
    $eventManager = $event->getApplication()->getEventManager();
    
$eventManager->getSharedManager()->attach('Zend\Mvc\Controller\AbstractActionController',
 \Zend\Mvc\MvcEvent::EVENT_DISPATCH, array($this, 'chooseLayout'), 100);
}

public function chooseLayout(\Zend\Mvc\MvcEvent $event)
{
    if ($someCondition) {
        $event->getTarget()->layout('layout/layout1.phtml');
    }else {
        $event->getTarget()->layout('layout/layout2.phtml');
    }
}

On 15/01/14 03:36, Julian Vidal wrote:
My app has the same URLs for the desktop and mobile versions. People don't
hit it directly, they go though Akamai first and Akamai in turn sets a
cookie to true or false whether the user is is using a mobile device or
not. So the real detection is carried out by Akamai.

I'm currently detecting this cookie in MvcEvent::EVENT_ROUTE and doing some
other things that I need to with it... BUT I would like to automate setting
the layout and template based on this cookie.

I can get to the template with
$mvcEvent->getViewModel()->setTemplate('foo')but I can't seem to find
the root template in this event. From the
controller I usually do $this->layout()->setTemplate('someLayout').

What am I missing?

Thanks!




-----------------------------


Registered Office: 15 Stukeley Street, London WC2B 5LT, England.
Registered in England number 1421223

This message is for the designated recipient only and may contain privileged, 
proprietary, or otherwise private information. If you have received it in 
error, please notify the sender immediately and delete the original. Any other 
use of the email by you is prohibited. Please note that the information 
provided in this e-mail is in any case not legally binding; all committing 
statements require legally binding signatures.


http://www.weareifp.com




--
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]


Reply via email to