Tip: Obtaining Request Parameters in Zend_View

I found it virtually impossible to obtain GET or POST request parameters in Zend_View without resorting to accessing the $_GET or $_POST variables. Directly accessing these variables within Zend_View is bad practice so it's been suppressed on purpose to keep processing where it should be - within the Controller. However it is possible to get hold of these variables properly and that is to pass them from the Controller.

Example. You have a query string that looks like this ?keyword=test and want to show it in your view, here's what to do:

MyController.php

public function indexAction() {
  $this->view->request = $this->getRequest();
}

my-controller/index.phtml

The keyword is <?= $this->request->keyword ?>

Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>