[英]How to wrap input element inside div in ZF2
我正在關注此鏈接 。
鑒於我有
echo $this->formRow($product->get('name'));
在源頭它顯示像
<label>Name of the product<input name="product[name]" required="required" type="text" value=""></label>
但我想要這樣
<div><label>Name of the product</label></div>
<div><input name="product[name]" required="required" type="text" value=""></div>
也許這個問題在某個地方被問到但我無法找到它。
我使用的是php 5.6
。
編輯:
根據答案,我能夠解決這個問題。 以下鏈接中的文檔。 我在這部分有問題
echo $this->formCollection($product->get('categories'));
我試過這樣的
echo "<div>".$this->formLabel($this->get('categories'))."</div>";
echo "<div>".$this->formInput($this->get('categories'))."</div>";
但它會引發致命的錯誤。
可捕獲的致命錯誤:第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="">
然后你可以在echo
使用div標簽。 所以這就是你想要的:
echo "<div>".$this->formLabel($form->get('name'))."</div>";
echo "<div>".$this->formInput($form->get('name'))."</div>";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.