cod*_*er3 1 zend-framework zend-form
我已经清理了表单的输入(textarea字段),当我在我的视图中显示它时,它出现如下:
< p>我要赢它!我期待在< br />比赛中心参加比赛.他的目的是通过与现代生活的幽默和挫折相关的工作,对舞台,屏幕和立体声进行交叉授粉.</p>
在我的控制器中我有这个:
public function init(){
$this->view->setEscape('html_entity_decode');
$this->view->setEscape('stripslashes');
}
Run Code Online (Sandbox Code Playgroud)
但只有一个有用,如果我擦除了一个setEscape,那么另一个工作,反之亦然.因此,如果我把它放在第一位但是html_entity_decode不能正常工作,我可以让striplashes工作,反之亦然
您需要定义自己应该用于转义的函数.例如,您可以在library/My/Tools.php中定义一个类My_Tools,如下所示:
<?php
#Tools.php
class My_Tools {
/**
* My custom escape function
*
* @param string $str String to be escaped
* @return string Escaped string
*/
static function myEscape($str) {
$str = html_entity_decode($str);
return stripslashes($str);
}
}
?>
Run Code Online (Sandbox Code Playgroud)
然后,您的init()可以具有以下形式:
public function init() {
require_once(APPLICATION_PATH . '/../library/My/Tools.php');
$this->view->setEscape(array('My_Tools', 'myEscape'));
}
Run Code Online (Sandbox Code Playgroud)
当然,最好将工具添加到Autoloader,但这只是一个例子.