zend-framework - 如何在 Zend Form Elements 中包含 js 和 css?

标签 zend-framework zend-form

我创建自己的 zend 表单元素 - App_Form_Element_Wysiwyg

<?php

class App_Form_Element_Wysiwyg extends Zend_Form_Element_Xhtml
{
    /**
     * Default form view helper to use for rendering
     * @var string
     */
    public $helper = 'wysiwyg';

}

然后我为所见即所得创建助手 - App_View_Helper_Wysiwyg

<?php

class App_View_Helper_Wysiwyg extends Zend_View_Helper_FormTextarea
{
    public function wysiwyg($name, $value = null, $attribs = null)
    {
        // Here I want to include js and css for wysiwyg editor
        ...
        $xhtml = '<textarea name="' . $this->view->escape($name) . '"'
                . ' id="' . $this->view->escape($id) . '"'
                . $disabled
                . $this->_htmlAttribs($attribs) . '>'
                . $this->view->escape($value) . '</textarea>';

        return $xhtml;
    }
}

如何为所见即所得编辑器包含 js 和 css 文件?

最佳答案

headScript() 帮助器允许您在 header 中添加或操作脚本标记。所以在你的助手中你可以这样做:

$this->view->headScript()->appendFile('/path/to/file.js');

然后确保您的布局在 head 部分的某个位置调用助手:

<?=$this->headScript()?>

输出 HTML。还有 headStyle() 帮助器,其工作方式类似,可用于 CSS。

相关文档:

关于zend-framework - 如何在 Zend Form Elements 中包含 js 和 css?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14946021/

相关文章:

php - 如果存在不存在的类,为什么 zend autoloader 测试会导致错误?

php - 在哪里可以找到 Zend_Form 的所有验证器和过滤器的列表?

php - 构造函数参数在 init 中不可用

zend-framework - 如何处理zend框架形式的多选框?

php - 文件上传 : Size validator or setMaxFileSize()

php - 添加多个相同类型的子表单

php - 我在哪里保存 Zend_Form 文件?

php - 在 zend 框架中发送电子邮件,在 css 中嵌入图像

php - Zend <dt> <dd> 装饰器 : what do I lose by removing them

php - Zend Form ViewScript 摆脱 dt 和 dd 标签?