I've written a helper in order to make my main nav. Part of this helper checks if there is a user logged in by checking if a user has been assigned to the view
if($this->view->user)
{
//do stuff
}
However when I call this helper in my layout script it is unable to access $this->view->user; it has NULL value (although var_dump($this->view returns the view object, jsut not with all the properties I assigned to it). It can only access the user data if, in the view script, I assign it to the layout, i.e.
$this->layout()->user = $this->user;
And then in the helper do
if($this->view->layout()->user)
{
//do stuff
}
Which is a pain as it means in each view script I have to add a line to pass the data to the layout.
Is there a way to enable helpers called in the layout script to access properties of the view?
edit*
Here's the source:
<?php
class Zend_View_Helper_MainNav extends Zend_View_Helper_Abstract {
public function mainNav()
{
if ($this->view->layout()->navType == 'none'){
$html = '<div id="nav"><a href="/" id="logo">Sum puzzles</a></div>';
} else if($this->view->layout()->navType == 'small'){
$html = '<div id="nav" class="small"><a href="/" id="logo">Sum puzzles</a><ul>' .
'<li><a href="/puzzle/view" class="button">play a puzzle</a></li>' .
'<li><a href="/sequence/play" class="button">puzzle sequences</a></li>' .
'<li><a href="/puzzle/create" class="button">create a puzzle</a></li>';
if(!$this->view->user)
{
$html .= '<li><a href="/teachers" class="button">teachers area</a></li>';
}
$html .='</ul></div>';
} else if($this->view->layout()->navType == 'large'){
$html = '<div id="nav" class="large"><a href="/" id="logo">Sum puzzles</a><ul>' .
'<li><a href="/sequence/play" class="playSequence">Play a sequence of puzzles</a></li>' .
'<li><a href="/puzzle/create" class="createPuzzle">Create your own puzzles</a></li>';
if(!$this->view->user)
{
$html .= '<li><a href="/teachers" class="teachersArea">teachers area</a></li>';
}
$html .= '</ul></div>';
}
return $html;
}
}