Thank you Frank, 
with your help I wrote this plugin that makes the navigation works as I needed, 
basically it checks if an xml page has a parameter that exists in the request, 
and eventually sets the param.

If needed, the "reset" xml custom param can be implemented. 

<?php 
/**
 * Fix per l'aggiunta dei parametri Request nelle url breadcrumbs
 * 
 * @author Sergio Rinaudo
 */
class My_Plugin_NavigationParamsFix extends Zend_Controller_Plugin_Abstract
{
    /**
     * PostDispatch Hook
     * 
     * @return void
     */
     public function postDispatch(Zend_Controller_Request_Abstract $request)
     {
           $params = $this->getRequest()->getParams();
         $container = Zend_Registry::get('Zend_Navigation');
        $this->_recursiveParamsSetter( $container, $params );
     }
     
     /**
      * Recursiveli apply params value to pages
      * 
      * @return void
      */
     protected function _recursiveParamsSetter( $container, $params ) {
           if( $container instanceof Zend_Navigation_Container ) {
            if( $container->hasChildren() ) {
                foreach( $container AS $page ) {
                      if( $page instanceof Zend_Navigation_Page_Mvc) {
                        $pageParams = $page->get('params');
                        $page->setParams( array_intersect_key($params, 
$pageParams) );
                       }
                     $this->_recursiveParamsSetter( $page, $params );
                }
            }
        }
    }
}

Sergio Rinaudo


> To: [email protected]
> Date: Tue, 4 Oct 2011 15:09:36 +0200
> From: [email protected]
> Subject: Re: [fw-general] XML Navigation: how to get params value from request
> 
> Am 04.10.2011, 14:50 Uhr, schrieb Sergio Rinaudo  
> <[email protected]>:
> 
> >
> > Dear ZF list,
> > I have this little problem with Zend Navigation and XML, my breadcrumbs  
> > look like this:
> >
> > home => users => customers-list => customer-branches =>  
> > customer-branch-edit
> >
> > To access "customer-branches" page I need to have an user_id param.
> > To access "customer-branch-edit" page I need to have an user_id param  
> > and also a branch_id param.
> >
> > If I am in the "customer-branch-edit" page I haven't found a way to make  
> > the breadcrumb link to "customer-branches" ( but also to  
> > "customer-branch-edit" )
> > render in the correct manner ( with the 'user_id' passed via GET ).
> >
> > I added the param "user_id" to the XML navigation
> >
> >                         <params>
> >                             <user_id></user_id>
> >                         </params>
> >
> > and even if I have the "reset" set to false ( <reset>false</reset> ),  
> > apparently there is no way to render the value from the request.
> >
> > For sure I am mistaking something.
> >
> > How to solve this?
> 
> For example: Create an controller plugin.
> 
> class Application_Plugin_Navigation extends Zend_Controller_Plugin_Abstract
> {
>      /**
>       *
>       * @param Zend_Controller_Request_Abstract $request
>       */
>      public function postDispatch(Zend_Controller_Request_Abstract $request)
>      {
>          // Check controller and action
>          if ('customer' == $request->getControllerName()
>              && 'branches' == $request->getActionName())
>          {
>              // Get navigation container
>              $container = Zend_Registry::get('Zend_Navigation');
> 
>              // Get page
>              $page = $container->findOneBy('route', $routeName);
> 
>              if ($page instanceof Zend_Navigation_Page_Mvc) {
>                  // Set parameter (ID)
>                  $page->setParams(array('user_id' =>  
> $request->getParam('id')));
>              }
>          }
>      }
> }
> 
> 
> I prefer naming conventions for all routes: "controllerAction" and  
> "moduleControllerAction".
> In your case: "customerBranches" and "customersList"
> 
> In the plugin you can check:
> 
> // Create route name
> $route = strtolower($request->getControllerName())
>         . ucfirst(strtolower($request->getActionName()));
> 
> // Check current route
> switch ($route) {
>      case 'customerBranches':
>      case 'customersList':
>          // ...
>          break;
> 
>      default:
>          break;
> }
> 
> http://framework.zend.com/manual/de/zend.controller.plugins.html
> 
> -- 
> List: [email protected]
> Info: http://framework.zend.com/archives
> Unsubscribe: [email protected]
> 
> 
                                                                                
  

Reply via email to