Zend Framework:在我的表单中插入DIV和Image

Nav*_*eed 3 zend-framework zend-form

我需要以我的zend形式插入这样的html代码:

<div class="myClass1" id="myId1" style="display: none;"><img src="images/myImage.jpg" /></div>
Run Code Online (Sandbox Code Playgroud)

以上html代码的zend框架中的代码是什么.我尝试使用Create_Element,但它总是在div标签内创建一个按钮.请举一个示例代码.谢谢

2ni*_*2ni 8

我创建了一个名为"html"的自定义元素.我将Html.php添加到/ Form/Element:


/** Zend_Form_Element_Xhtml */
require_once 'Zend/Form/Element/Xhtml.php';

/**
 * HTML form element
 * 
 */
class Zend_Form_Element_Html extends Zend_Form_Element_Xhtml
{
    /**
     * Default form view helper to use for rendering
     * @var string
     */
    public $helper = 'formHtml';
}

其次,我必须添加一个视图助手FormHtml.php(我把它放在application/views/helpers中):


/**
 * Abstract class for extension
 */
require_once 'Zend/View/Helper/FormElement.php';

/**
 * Helper to show HTML
 *
 */
class Zend_View_Helper_FormHtml extends Zend_View_Helper_FormElement
{
    /**
     * Helper to show a html in a form
     *
     * @param string|array $name If a string, the element name.  If an
     * array, all other parameters are ignored, and the array elements
     * are extracted in place of added parameters.
     *
     * @param mixed $value The element value.
     *
     * @param array $attribs Attributes for the element tag.
     *
     * @return string The element XHTML.
     */
    public function formHtml($name, $value = null, $attribs = null)
    {
        $info = $this->_getInfo($name, $value, $attribs);
        extract($info); // name, value, attribs, options, listsep, disable

        // Render the button.
        $xhtml = 'view->escape($id) . '">'
            . $this->_htmlAttribs($attribs)
            . $this->view->escape($value) . '';

        return $xhtml;
    }
}

然后,您可以将html添加到表单中,如下所示:


$form->createElement('html', 'someid', array('value'=>'gna

foobar

'));

可能会有一些更简化.