How do I access the value of a URL variable in Zend view?

I want to access the value of a specific variable (in url) in my view helper. How can i do this?

I can get my controller name with: Zend_Controller_Front :: getInstance () -> getRequest () -> getControllerName (); but I have no idea about the variable ...

Thanks in advance!

+2


a source to share


2 answers


The most obvious are:

// will retrieve any param set in the request (might even be route param, etc)
Zend_Controller_Front::getInstance()->getRequest()->getParam( 'someParam' );

// $_POST
Zend_Controller_Front::getInstance()->getRequest()->getPost( 'somePostParam' );

// $_GET
Zend_Controller_Front::getInstance()->getRequest()->getQuery( 'someQueryStringParam' );

      



Also check out the API docs: Zend_Controller_Request_Http
Overview
(1.10)

+2


a source


You can get the request object from Zend_Controller_Front

:

abstract class App_View_Helper_Abstract extends Zend_View_Helper_Abstract
{
   /**
    * @var Zend_Controller_Front
    */
   private $_frontController;

   /**
    * Convience function for getting a request parameter from the request
    * object in a view helper
    * @param string $name The name of the request parameter
    * @param mixed $default The value to return if $name is not defined in the
    * request
    * @return mixed The value of parameter $name in the request object,
    * or $default if $name is not defined in the request
    */
   public function getRequestVariable ($name, $default = null)
   {
      return $this->getRequest()->getParam($name, $default);
   }

   /**
    *
    * @return Zend_Controller_Request_Abstract
    */
   public function getRequest ()
   {
      return $this->getFrontController()->getRequest();
   }

   /**
    * @return Zend_Controller_Front
    */
   private function getFrontController ()
   {
      if ( empty($this->_frontController) )
      {
         $this->_frontController = Zend_Controller_Front::getInstance();
      }
      return $this->_frontController;
   }
}

      



Now you can use the getRequestVariable

-method from all view helpers extending App_View_Helper_Abstract

+4


a source







All Articles