gpt4 book ai didi

zend-framework - Zend 框架 : Insert DIV and Image in my form

转载 作者:行者123 更新时间:2023-12-04 06:43:39 25 4
gpt4 key购买 nike

我需要在我的 zend 表单中插入这样的 html 代码:

<div class="myClass1" id="myId1" style="display: none;"><img src="images/myImage.jpg" /></div>

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

最佳答案

我创建了一个名为“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';
}

其次,我必须添加一个 View 助手 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

'));

可能还有一些更简单的可能。

关于zend-framework - Zend 框架 : Insert DIV and Image in my form,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1238377/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com