English 中文(简体)
Zend框架,getParams->setParams
原标题:Zend Framework, getParams -> setParams

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(strip_tags($value));
}
$this->setRequest()->setParams($clear);//error, Argument 1 passed to Zend_Controller_Action::setRequest() must be an instance of Zend_Controller_Request_Abstract

所以问题是如何在整个页面中更改参数,所以如果我想在任何地方访问这些数据,我可以确保它们是安全的。是否可以仅将该参数更改为索引控制器。提前感谢!

最佳回答

将setRequest()更改为getRequest()。

 $this->getRequest()->setParams($clear);
问题回答

您可能想看看Zend_Filter_Input用于验证和筛选用户输入。我认为,如果您只想在模型中保存数据,那么更改请求参数是不好的做法。相反,让Zend_Filter-Input来处理它,并将结果提供给您的模型。

如果您要转发到另一个控制器操作,该怎么办?你将无法访问未更改的内容。当其他人加入你的项目时,他/她可能不会期望请求参数被更改。

试试这个:

$request = $this->getRequest();
$clear = $request->getParams();
foreach ($clear as $key => $value) {
    $clear[$key]=trim(strip_tags($value));
}
$request->setParams($clear);

换句话说,您不想替换请求(用setRequest()),而只想用setParams()替换params。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签