Reputation: 1734
I have developed a web application with zf2. And I have also developed it for mobile devices. But I cannot decide how can I pass this variable to controller visitor is mobile or not ... for example I want to reach to controller to isMobile or not from view. Or do you suggest any other way?
//Application\Module.php
public function onBootstrap(MvcEvent $e){
$mobileDetect = $serviceManager->get('MobileDetect'); //Retrieve "\Mobile_Detect" object
//I want to reach to this value (isMobile or not) from my view. but how can do this?
$isMobile = $mobileDetect->isMobile();
}
Upvotes: 1
Views: 139
Reputation: 1274
It seems that you want to access the $isMobile
variable in the view files.
If that is so, then try this -
after $isMobile = $mobileDetect->isMobile();
write -
$e->getViewModel()->setVariables(
array(
'isMobile' => $isMobile,
)
);
then in any view files, you can access it as $isMobile
and you will get the set value.
I hope this helps.
Upvotes: 1