Zend framework Zend:如何使用setDecorators()创建自定义表单元素?
我需要如下html格式:Zend framework Zend:如何使用setDecorators()创建自定义表单元素?,zend-framework,zend-form,decorator,Zend Framework,Zend Form,Decorator,我需要如下html格式: <form> <div class="es_form_txt">Name</div> <div class="es_form"><input type="text" value="" class="email1"></div> <div class="clear1"></div> <div class="es_form_txt">Gender</div>
<form>
<div class="es_form_txt">Name</div>
<div class="es_form"><input type="text" value="" class="email1"></div>
<div class="clear1"></div>
<div class="es_form_txt">Gender</div>
<div class="es_form">
<input type="radio" value="" name=""> Male
<input type="radio" value="" name=""> Female
<input type="radio" value="" name=""> Other
</div>
<div class="clear1"></div>
<div class="es_form_txt">Country Code</div>
<div class="es_form"><input type="text" value="" class="email1"></div>
<div class="clear1"></div>
<div class="es_form_txt">Phone</div>
<div class="es_form"><input type="text" value="" class="email1"></div>
<div class="clear1"></div>
<div class="clear1"></div>
<div class="es_form"> </div>
<div class="es_form"><input type="button" class="button" value="Update"></div>
<div class="clear"></div>
</form>
名称
性别
男性
女性
其他
国家代码
电话
我在这里尝试了各种各样的解决方案,但都不起作用!有人能给我指出正确的方向吗?我发现当我需要显示特定的HTML时,使用最可靠的解决方案通常是使用 使用Zend_表单构建一个标准表单
<?php
//application/forms/Search.php
class Application_Form_Search extends Zend_Form
{
public function init()
{
$this->setMethod('POST');
//assign the view script to the decorator, this can also be done in the controller
$this->setDecorators(array(
array('ViewScript', array(
'viewScript' => '_searchForm.phtml'
))
));
// create new element
$query = $this->createElement('text', 'query');
// element options
$query->setLabel('Search Keywords');
// add the element to the form
$this->addElement($query);
//submit element
$submit = $this->createElement('submit', 'search');
$submit->setLabel('Search Site');
$submit->setDecorators(array('ViewHelper'));
$this->addElement($submit);
}
}
当前呈现为:
<article class="search">
<form action="/video/index/display" method="post">
<table>
<tr>
<th>
<dt id="query-label">
<label for="query" class="optional">Search Keywords</label>
</dt>
</th>
</tr>
<tr>
<td>
<input type="text" name="query" id="query" value="" placeholder="Movie Title" size="20">
</td>
</tr>
<tr>
<td>
<input type="submit" name="search" id="search" value="Search Video Collection!">
</td>
</tr>
</table>
</form>
</article>
搜索关键字
需要进行一些实验才能获得所需的准确输出。这很好,但我想知道在我的视图文件中使用php代码是否是一种好的做法——我真的不喜欢它。无论如何,您的解决方案是一个快速的解决方案:)在视图文件中无法避免使用php,这就是为什么它们是.phtml(php html)。如果您愿意,您可以使用单独的模板系统,但这可能需要付出大量的努力,但回报很少。
<article class="search">
<form action="/video/index/display" method="post">
<table>
<tr>
<th>
<dt id="query-label">
<label for="query" class="optional">Search Keywords</label>
</dt>
</th>
</tr>
<tr>
<td>
<input type="text" name="query" id="query" value="" placeholder="Movie Title" size="20">
</td>
</tr>
<tr>
<td>
<input type="submit" name="search" id="search" value="Search Video Collection!">
</td>
</tr>
</table>
</form>
</article>