Somebody
Somebody

Reputation: 9645

Zend Framework - how to remove param from request?

How to completely remove param from request object inside controller?

Is there a method for this?

Or i should pick all params, loop through them, remove and then set them all again?

This is Sparta? :D

Upvotes: 3

Views: 5762

Answers (3)

Tom Shaw
Tom Shaw

Reputation: 101

The ZF2 way of doing things.

if ($request->getPost()->offsetExists('myparam')) {
    $request->getPost()->offsetUnset('myparam')
} 

Upvotes: 1

Fluxine
Fluxine

Reputation: 93

I add that if your request is an HTTP request then you will not be able to alter parameters coming from GET or POST parameters. These parameters are virtually added to all parameters via overriden accessors, so setParam() on a these requests with a GET or POST variable key as parameters will simply do nothing because setParam() tests whether the key is present in the "intrinsic" parameters of the requets, not HTTP ones.

To alter these kind of paramaters you have to unset keys directly from the $_GET or $_POST php arrays.

Upvotes: 1

Elzo Valugi
Elzo Valugi

Reputation: 27876

To remove a parameter use unset php function or setParam() with a NULL value. If you want to loop use getParams() function from the request object.

Update

As params is a protected variable invoke __unset() to have access to inaccesible properties. You will have to extend Zend_Controller_Request_Abstract for that.

Upvotes: 7

Related Questions