I'm using zend MVC 3.1.1 and trying to pass variables from the called controller action to the layout but having real difficulties finding a way to do so. I haven't found a solution online for this problem.
Here is my base controller 'render' method that gets called to create the view model.
protected function render ( array $data = array () ) {
$controller = '';
$action = '';
$controller = strtolower( preg_replace( "/^(.*)\\\/", "", $controller ) );
$data[ 'controller' ] = $controller;
$data[ 'action' ] = $action;
$viewModel = new ViewModel( $data );
$viewModel->setTemplate( $controller . "/{$action}.php" );
return $viewModel;
}
And here is a snipped of my layout.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title><!-- I WANT TO PUT VARIABLE HERE --></title>
</head>
<body>
<?=$this->content?>
</body>
</html>
How can I pass a variable from the controller 'render' action, or anywhere else in the execution, and have access to it in the same way I do to '$this->content'?
Thank you.