Hi,
i´m a little bit confused by reading all this posts an tutorials about staring with Zend, because there a so many different ways to solve a problem.
I only need a feedback about my code to know if iam on the right way:
To simply get a (hard coded) Navigation for my side (depending on who is logged in) i build a Controller Plugin with a postDispatch method that holds following code:
public function postDispatch(Zend_Controller_Request_Abstract $request)
{
$menu = new Menu();
//Render menu in menu.phtml
$view = new Zend_View();
//NEW view -> add View Helper
$prefix = 'My_View_Helper';
$dir = dirname(__FILE__).'/../../View/Helper/';
$view->addHelperPath($dir,$prefix);
$view->setScriptPath('../application/default/views/scripts/menu');
$view->menu = $menu->getMenu();
$this->getResponse()->insert('menu', $view->render('menu.phtml'));
}
Is it right that i need to set the helper path once again? I did this in a Plugin Controller named ViewSetup. There i do some setup for the view like doctype, headlinks, helper paths...(This step is from the book: Zend Framework in Action)
The Menu class which is initiated looks like this:
class Menu
{
protected $_menu = array();
/**
* Menu for notloggedin and logged in
*/
public function getMenu()
{
$auth = Zend_Auth::getInstance();
$view = new Zend_View();
//check if user is logged in
if(!$auth->hasIdentity()) {
$this->_menu = array(
'page1' => array(
'label' => 'page1',
'title' => 'page1',
'url' => $view->url(array('module' => 'pages','controller' => 'my', 'action' => 'page1'))
),
'page2' => array(
'label' => 'page2',
'title' => 'page2',
'url' => $view->url(array('module' => 'pages','controller' => 'my', 'action' => 'page2'))
),
'page3' => array(
'label' => 'page3',
'title' => 'page3',
'url' => $view->url(array('module' => 'pages','controller' => 'my', 'action' => 'page3'))
),
'page4' => array(
'label' => 'page4',
'title' => 'page4',
'url' => $view->url(array('module' => 'pages','controller' => 'my', 'action' => 'page4'))
),
'page5' => array(
'label' => 'page5',
'title' => 'page5',
'url' => $view->url(array('module' => 'pages','controller' => 'my', 'action' => 'page5'))
)
);
} else {
//user is vom type 'client'
//..
}
return $this->_menu;
}
}
Here´s my view script:
<ul id="mainmenu">
<?php echo $this->partialLoop('menuItem.phtml',$this->menu) ?>
</ul>
This is working so far. My question is: is it usual to do it this way, is there anything to improve? I´m new to Zend and in the web are many deprecated tutorials which often is not obvious. Even the book is already deprecated where the autoloader is mentioned.
Many thanks in advance