How to force Zend_Navigation_Page_Mvc to generate an href

52 views Asked by At

I've come across a strange issue with Zend_Navigation_Page_Mvc. When I try to render the anchor tag, the URL seems to be cached from another instance on the page, therefore the href is incorrect.

To create the instance in the action I want to return to:

$request = $this->getRequest();

$back = new Zend_Navigation_Page_Mvc(
    array(
        'module'     => $request->getModuleName(),
        'controller' => $request->getControllerName(),
        'action'     => $request->getActionName(),
        'params'     => $params, // an array of params to pass
        'label'      => 'Back to listings',
        'class'      => 'back'
    )
);

I then store this in the session and later retrieve it to provide a back button. So in the action I get the instance back from the session and assign it to the view. In the view, I render a navigation using echo $this->navigation(new Zend_Navigation(array($this->back)));

A var_dump of $this->back produces this:

object(Zend_Navigation_Page_Mvc)[132]
  protected '_action' => string 'index' (length=5)
  protected '_controller' => string 'specialcall' (length=11)
  protected '_module' => string 'admin' (length=5)
  protected '_params' => 
    array (size=0)
      empty
  protected '_route' => null
  protected '_resetParams' => boolean true
  protected '_encodeUrl' => boolean true
  protected '_active' => boolean false
  protected '_scheme' => null
  protected '_hrefCache' => string '/digitallearning/admin/specialcall/view' (length=39)
  protected '_label' => string 'Back to listings' (length=16)
  protected '_fragment' => null
  protected '_id' => null
  protected '_class' => string 'back' (length=4)
  protected '_title' => null
  protected '_target' => null
  protected '_accesskey' => null
  protected '_rel' => 
    array (size=0)
      empty
  protected '_rev' => 
    array (size=0)
      empty
  protected '_order' => null
  protected '_resource' => null
  protected '_privilege' => null
  protected '_visible' => boolean true
  protected '_parent' => 
    object(Zend_Navigation)[130]
      protected '_pages' => 
        array (size=1)
          '00000000219cad71000000015ca8a15d' => 
            &object(Zend_Navigation_Page_Mvc)[132]
      protected '_index' => 
        array (size=1)
          '00000000219cad71000000015ca8a15d' => int 0
      protected '_dirtyIndex' => boolean false
  protected '_properties' => 
    array (size=0)
      empty
  protected '_customHtmlAttribs' => 
    array (size=0)
      empty
  protected '_pages' => 
    array (size=0)
      empty
  protected '_index' => 
    array (size=0)
      empty
  protected '_dirtyIndex' => boolean false

Calling var_dump with $this->back->getHref(); produces unexpected results:

string '/digitallearning/admin/specialcall/view' (length=39)

view is the current action, but as you can see from _action above, it's not the set action.

It appears that the href is being taken from a cache (see _hrefCache above). So my question is how can I force it to generate the href instead of taking it from its cache?

0

There are 0 answers