Zend framework zend_Filter_StripTags的通用对象zend框架,可在整个应用程序中使用?
我正试图在bootstrap中创建一个函数来初始化Zend_Filter_StripTags的对象,这样我就可以在整个应用程序中使用它的对象Zend framework zend_Filter_StripTags的通用对象zend框架,可在整个应用程序中使用?,zend-framework,Zend Framework,我正试图在bootstrap中创建一个函数来初始化Zend_Filter_StripTags的对象,这样我就可以在整个应用程序中使用它的对象 protected function _initHtmlFilter() { $allowedTags = array('p','b','br','strong'); // Allowed tags $allowedAttributes = array('href'); // Allowed attributes $stripTags =
protected function _initHtmlFilter() {
$allowedTags = array('p','b','br','strong'); // Allowed tags
$allowedAttributes = array('href'); // Allowed attributes
$stripTags = new Zend_Filter_StripTags($allowedTags,$allowedAttributes);
}
但我无法在任何控制器中使用此对象($stripTags)。我将为此创建控制器操作帮助程序:
class My_Controller_Action_Helper_StripTags extends
Zend_Controller_Action_Helper_Abstract
{
/**
* StripTags
*
* @param string $input String to strip tags from
*
* @return string String without tags
*/
public function stripTags($input)
{
$allowedTags = array('p','b','br','strong'); // Allowed tags
$allowedAttributes = array('href'); // Allowed attributes
$stripTags = new Zend_Filter_StripTags($allowedTags,$allowedAttributes);
// return input without tags
return $stripTags->filter($input);
}
}
// example in indexAction
$noTags = $this->_helper->stripTags('<h2>TEST</h2>');
protected function _initHtmlFilter() {
$allowedTags = array('p','b','br','strong'); // Allowed tags
$allowedAttributes = array('href'); // Allowed attributes
$stripTags = new Zend_Filter_StripTags($allowedTags,$allowedAttributes);
Zend_Registry::set('zend_strip_tags', $stripTags);
}
您可以为此使用zend注册表:
class My_Controller_Action_Helper_StripTags extends
Zend_Controller_Action_Helper_Abstract
{
/**
* StripTags
*
* @param string $input String to strip tags from
*
* @return string String without tags
*/
public function stripTags($input)
{
$allowedTags = array('p','b','br','strong'); // Allowed tags
$allowedAttributes = array('href'); // Allowed attributes
$stripTags = new Zend_Filter_StripTags($allowedTags,$allowedAttributes);
// return input without tags
return $stripTags->filter($input);
}
}
// example in indexAction
$noTags = $this->_helper->stripTags('<h2>TEST</h2>');
protected function _initHtmlFilter() {
$allowedTags = array('p','b','br','strong'); // Allowed tags
$allowedAttributes = array('href'); // Allowed attributes
$stripTags = new Zend_Filter_StripTags($allowedTags,$allowedAttributes);
Zend_Registry::set('zend_strip_tags', $stripTags);
}
并且可以在任何地方访问它,如:
Zend_Registry::get('zend_strip_tags');
我知道了,我也可以用Zend_注册表。