0

アプリケーション全体でそのオブジェクトを使用できるように、Zend_Filter_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) を使用できません。

4

2 に答える 2

1

このためのコントローラー アクション ヘルパーを作成します。

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>');

application.ini にヘルパーへのパスを追加する必要があります。

resources.frontController.actionhelperpaths.My_Controller_Action_Helper_ = "My/Controller/Action/Helper"
于 2013-01-09T10:47:58.633 に答える