gpt4 book ai didi

zend-framework - 仅渲染
标签

转载 作者:行者123 更新时间:2023-12-04 08:26:36 25 4
gpt4 key购买 nike

有什么方法可以只渲染开始<form> Zend_Form 对象的标签?

print $this->registerForm->renderForm();

渲染 <form></form> ,我只需要<form>

编辑:

在 Asleys 可能的解决方案之后,我为 My_Form 类编写了这个

public function renderFormOpen() {
return str_replace('</form>', '', $this->renderForm());
}

public function renderFormClose() {
return '</form>';
}

在查看 ZF 库中的代码之后,我仍然在寻找 ZF 的瘦身方式,尽管我认为没有任何方法。

最佳答案

可以编写一个自定义表单装饰器,它使用仅呈现打开表单标签的自定义 View 助手。但我认为这有点矫枉过正。
只需“硬编码”表单标签并使用 View 中表单变量提供的数据填充属性。

<!--in your view-template -->
<form action="<?php echo $this->form->getAction() ?>"
enctype="<?php echo $this->form->getEnctype() ?>"
method="<?php echo $this->form->getMethod() ?>"
id="<?php echo $this->form->getId() ?>"
class="<?php echo $this->form->getAttrib('class') ?>" >

<!--in case your products are represented as elements -->
<?php foreach ($this->form->getElements() as $element): ?>
<?php echo $element ?>
<?php endforeach; ?>

<!--in case your products are represented as displayGroups -->
<?php foreach ($this->form->getDisplayGroups() as $displayGroup): ?>
<?php echo $displayGroup ?>
<?php endforeach; ?>

<!--in case your products are represented as subforms -->
<?php foreach ($this->form->getSubforms() as $subform): ?>
<?php echo $subform ?>
<?php endforeach; ?>

<!--in case your products are rendered by a view helper -->
<?php foreach ($this->products as $product): ?>
<?php echo $this->renderProduct($product) ?>
<?php endforeach; ?>
</form>

只是为了好玩,矫枉过正

// Get your products form
$form = new Form_Products();
// Add custom prefix path
$form->addPrefixPath('Foobar_Form_Decorator', 'Foobar/Form/Decorator', 'decorator');
// Set OnlyOpenTagForm-ViewHelper for FormDecorator
$form->getDecorator('Form')->setHelper('OnlyOpenTagForm');

// copy Zend/View/Helper/Form to Foobar/Form/Decorato/OnlyOpenTagForm.php
// In OnlyOpenTagForm.php
// replace Zend_View_Helper_Form with Foobar_View_Helper_OnlyOpenTagForm
// replace method "form" with onlyOpenTagForm"
// replace
if (false !== $content) {
$xhtml .= $content
. '</form>';
}
// with:
if (false !== $content) {
$xhtml .= $content;
}

完成! - Java-Guys 会喜欢的 ;)

关于zend-framework - 仅渲染 <form> 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3250681/

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