Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 694003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:48:44+00:00 2026-05-14T02:48:44+00:00

I´m a little bit confused by reading all the posts and tutorials about starting

  • 0

I´m a little bit confused by reading all the posts and tutorials about starting with Zend, because there a so many different ways to solve a problem.

I just need some feedback about my code to know if I am on the right track.

To simply get a (hard coded) Navigation for my site (depending on who is logged in) I build a Controller Plugin with a postDispatch method:

 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 again?
I did this in a Plugin Controller named ViewSetup. There I do some setup for the view like doctype, headlinks, and 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 I’ve seen deprecated tutorials on the web which often are not obvious. Even the book is already deprecated where the autoloader is mentioned.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T02:48:44+00:00Added an answer on May 14, 2026 at 2:48 am

    You shouldn’t be creating a new view. Since you have already created the View object in your Boostrap (and used it to render the rest of the site) you should fetch the already created view object.

    If you are using Zend_Application_Resource to setup your view in the bootstrap you can fetch it like this:

    $view = Zend_Controller_Front::getInstance()
        ->getParam('bootstrap')
        ->getResource('view');
    

    This way there is no need to set the view helper path again and create another view object.

    If you are not using the Zend_Application to boostrap your app you could try something like this:

    $view = Zend_Layout::getMvcInstance()->getView();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am little bit confused about use of destructor in c#. In my knowledge
I've read a little bit about unit testing and was wondering how YOU unit
I've been reading recently about DI and IoC in C++. I am a little
I have been reading about bit operators in Objective-C in Kochan's book, Programming in
I've been reading a fair bit about the performance of using LINQ rather than
Little bit confused... I am trying to track mailto links being clicked, but constantly
hi i am little bit confused in valu type or referance type... for instance
I'm a little bit confused concerning variable updates in XQuery: On [1] it says:
I'am a little bit confused what is better to use debug or write unit
I'm doing a little bit of work on a horrid piece of software built

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.