Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...

When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Adding GET and POST parameters

Adding GET parameters to an HTTP request is quite simple, and can be done either by specifying them as part of the URL, or by using the setParameterGet() method. This method takes the GET parameter's name as its first parameter, and the GET parameter's value as its second parameter. For convenience, the setParameterGet() method can also accept a single associative array of name => value GET variables - which may be more comfortable when several GET parameters need to be set.

Example 476. Setting GET Parameters

// Setting a get parameter using the setParameterGet method

// This is equivalent to setting such URL:

// Adding several parameters with one call
'first_name'  => 'Bender',
'middle_name' => 'Bending'
=> 'Mexico',

While GET parameters can be sent with every request method, POST parameters are only sent in the body of POST requests. Adding POST parameters to a request is very similar to adding GET parameters, and can be done with the setParameterPost() method, which is similar to the setParameterGet() method in structure.

Example 477. Setting POST Parameters

// Setting a POST parameter

// Setting several POST parameters, one of them with several values
'language'  => 'es',
'country'   => 'ar',
'selection' => array(453280)

Note that when sending POST requests, you can set both GET and POST parameters. On the other hand, while setting POST parameters for a non-POST request will not trigger and error, it is useless. Unless the request is a POST request, POST parameters are simply ignored.

Zend Framework