以zend形式添加img标签 [英] adding img tag in zend form

查看:149
本文介绍了以zend形式添加img标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm building a form with a class extending Zend_Form.How can I add an img tag inside the form?I also need to add a class to it and align attribute

这是我想要达到的最终结果:

This is the final result I want to achieve:

<span class="myElement"><img src="myPath" align="middle" class="myClass"/>
<input type="text"></span>

我没有找到关于Zend_Form_Element_Image文档的更多信息

I didnt find much about Zend_Form_Element_Image's documentation

谢谢

Luca

推荐答案

有库/申请/表格/Element/Img.php

Have in library/Application/Form/Element/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',
        ));
    }
}

在application / view / helpers / FormImg.php

In 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;
    }
}

在表格中:

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

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

Note: paths are subject to change in your particular application.

这篇关于以zend形式添加img标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆