Zend framework2 如何在ZF2中将输入元素包装到div中

Zend framework2 如何在ZF2中将输入元素包装到div中,zend-framework2,Zend Framework2,我跟在后面 在我看来 <label>Name of the product<input name="product[name]" required="required" type="text" value=""></label> echo$this->formRow($product->get('name') 并且在源代码中显示为 <label>Name of the product<input name="product[name]" r

我跟在后面

在我看来

<label>Name of the product<input name="product[name]" required="required" type="text" value=""></label>
echo$this->formRow($product->get('name')

并且在源代码中显示为

<label>Name of the product<input name="product[name]" required="required" type="text" value=""></label>
我试过这样做

echo "<div>".$this->formLabel($this->get('categories'))."</div>";
echo "<div>".$this->formInput($this->get('categories'))."</div>";
echo'.$this->formLabel($this->get('categories'));
回显“$this->formInput($this->get('categories')”;
但它抛出了致命的错误

可捕获的致命错误:第39行的/opt/lampp/htdocs/zend2/module/Test/View/Test/index/testform.phtml中,类Zend\Form\View\Helper\FormLabel的对象无法转换为字符串


如何修复此问题?

您可以使用下面的代码,而不是
$this->formRow
,并可以分离标签并输入两者

echo $this->formLabel($form->get('name'));
echo $this->formInput($form->get('name'));
它将输出以下内容:

<label>Name of the product</label>
<input name="product[name]" required="required" type="text" value="">

您可以使用下面的代码,而不是
$this->formRow
,并可以分离标签和输入两者

echo $this->formLabel($form->get('name'));
echo $this->formInput($form->get('name'));
它将输出以下内容:

<label>Name of the product</label>
<input name="product[name]" required="required" type="text" value="">

谢谢,你能给我发送
formLabel
的ref吗?@Hiranya检查这个链接:使用上面的ref,我正在尝试为
echo$this->formCollection($product->get('categories')做同样的事情
,但我如何才能使它在
集合中分离出来呢??您要求将标签和输入分开。我说得对吗?是的,与
名称字段
相同,但它是用
集合定义的
谢谢,你能给我发送
formLabel
的ref吗?@Hiranya检查这个链接:使用上面的ref,我正试图对
echo$this->formCollection($product->get('categories')做同样的操作
,但我如何才能使它在
集合中分离出来呢??您要求将标签和输入分开。我说得对吗?是的,与
名称字段
相同,但它是用
集合
定义的