I was wondering if it is possible or how to be able to define a ViewModel in the Application module and pass it to display in the layout.phtml in Zend Framework 2. Here is the code for the Application Controller:
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\Session\Container;
use Zend\View\Model\ViewModel;
class IndexController extends AbstractActionController
{
public function indexAction()
{
$container = new Container('session');
return new ViewModel(array('username' => $container->username,
'password' => $container->password));
}
}
This is the layout.phtml page I am trying to get username to display
<ul class="nav navbar-nav navbar-right">
<li><p class="navbar-text" style="font-family: Papyrus, fantasy; font-size: 20px;">
<?php echo $username; ?></p></li>
</ul>
Any help would be appreciated.