0

I had a read of the documentation, but couldn't see an example of how it would be possible to use the variable in traditional PHP style of $_POST['var']

I'm pretty sure my URL is legit:

domain.com/module/controller/action/var/value/

Using the above as an example:

$var didn't work

$_POST['var'] didn't work

How is it done?

2 Answers 2

4

As presented in zend controller's documentation page you can retrieve parameters like this:

public function userinfoAction()
{
    $request = $this->getRequest();
    $username = $request->getParam('username');

    $username = $this->_getParam('username');
}

You should also note that request documentation states:

In order to do some of its work, getParam() actually retrieves from several sources. In order of priority, these include: user parameters set via setParam(), GET parameters, and finally POST parameters. Be aware of this when pulling data via this method.

If you wish to pull only from parameters you set via setParam(), use the getUserParam(). Additionally, as of 1.5.0, you can lock down which parameter sources will be searched. setParamSources() allows you to specify an empty array or an array with one or more of the values '_GET' or '_POST' indicating which parameter sources are allowed (by default, both are allowed); if you wish to restrict access to only '_GET' specify setParamSources(array('_GET')).

Sign up to request clarification or add additional context in comments.

Comments

2

$this->_request->getParam('paramName', $defaultValueToReturnIfParamIsNotSet);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.