以zend形式添加img标签

luc*_*uca 8 php forms zend-framework image

我正在使用扩展Zend_Form的类构建一个表单.如何在表单中添加一个img标签?我还需要为它添加一个类并对齐属性

这是我想要实现的最终结果:

<span class="myElement"><img src="myPath" align="middle" class="myClass"/>
<input type="text"></span>
Run Code Online (Sandbox Code Playgroud)

我没有找到关于Zend_Form_Element_Image的文档

谢谢

卢卡

ako*_*ond 10

有图书馆/申请表/表格/元素/ Img.php

class Application_Form_Element_Img extends Zend_Form_Element_Xhtml
{
    public $helper = 'formImg';

    public function loadDefaultDecorators ()
    {
        parent::loadDefaultDecorators ();
        $this->removeDecorator ('Label');
        $this->removeDecorator ('HtmlTag');

        $this->addDecorator('HtmlTag', array (
        'tag'   => 'span',
        'class' => 'myElement',
        ));
    }
}
Run Code Online (Sandbox Code Playgroud)

在application/view/helpers/FormImg.php中

class Zend_View_Helper_FormImg extends Zend_View_Helper_FormElement
{
    public function formImg ($name, $value, $attribs = null)
    {
        $info = $this->_getInfo($name, $value, $attribs);

        $xHtml = '<img'
                . $this->_htmlAttribs ($attribs)
                . ' />';

        return $xHtml;
    }
}
Run Code Online (Sandbox Code Playgroud)

在你的形式:

    $this->addElement ('img', 'myimage', array (
        'src'           => '/images/download.png',
        'align'         => 'right',
    ));
Run Code Online (Sandbox Code Playgroud)

注意:路径可能会在您的特定应用程序中发生变化.