title: Zend Framework 2 set global module variable
body: <p>I want to make it so the variable "user" is global to all modules, so I've added this code</p>
  
  <pre><code>public function onBootstrap(MvcEvent $e)
  {
      $eventManager        = $e-&gt;getApplication()-&gt;getEventManager();
  
      $e-&gt;getViewModel()-&gt;setVariable('user',$e-&gt;getApplication()-&gt;getServiceManager()-&gt;get('auth_service')-&gt;getIdentity());
  }
  </code></pre>
  
  <p>It works fine for the layout file, meaning that if I do var_dump($user) in the layout.phtml it will output the expected results, although in a view doing the same results in </p>
  
  <p>Notice: Undefined variable: user in C:\webserver\apache\htdocs...</p>
  
  <p>Any help on why this is happening? Am I doing something wrong?</p>