Jiew Meng Jiew Meng - 6 months ago 25
PHP Question

Zend Framework: Can i just get GET params?

In Zend Framework, most of the time to get a param, i will use

// from controller
$this->getRequest()->getParam('key');


but how can i get just GET params using the 'Zend' way? Or do i just use
$_GET
? Is there any difference between

$this->getRequest()->getParam('key');


vs

$_GET['key'];

Answer

Use getQuery():

$this->_request->getQuery('key');

Other methods available include

  • getParam()
  • getQuery()
  • getPost()
  • getCookie()
  • getServer()
  • getEnv()

getParam() checks user params first, then $_GET, and then $_POST, returning the first match found or null.

Try to avoid accessing the superglobals directly.