I'm new with Zend Framework but i didn't find solution yet. Problem is next: I have form, when is submitted user goes to index controller and there is an add action. I know how i can get params, This is what i want do:
$clear = $this->getRequest()->getParams();
foreach ($clear as $key => $value) {
$clear[$key]=trim(stri开发者_高级运维p_tags($value));
}
$this->setRequest()->setParams($clear);//error, Argument 1 passed to Zend_Controller_Action::setRequest() must be an instance of Zend_Controller_Request_Abstract
So question is how to change in whole page that params, so if i want anywhere access that data i could be sure that they are safe. And is it possible to change that params only to index controller. Thanks in advance!
You might want to take a look at Zend_Filter_Input for validating and filtering user input. I think it's bad practice to alter the request parameters if you're only going to save data in your model. Instead, let Zend_Filter_Input take care of it and feed the result to your model.
What if you were to forward to another controller action? You wouldn't have access to the unaltered content. And when someone else buds in your project he/she might not expect the request parameters to have been altered.
Change setRequest() to getRequest().
$this->getRequest()->setParams($clear);
Try this:
$request = $this->getRequest();
$clear = $request->getParams();
foreach ($clear as $key => $value) {
$clear[$key]=trim(strip_tags($value));
}
$request->setParams($clear);
In other words, you don't want to replace the request (with setRequest()
) but merely replace the params with setParams()
.
精彩评论