2017-02-17 74 views
1

我正在關注this link如何在ZF2中將div內的輸入元素換行

鑑於我有

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

編輯:

根據答案我能夠解決這個issue.Following文檔中this link。我有問題,在這部分

echo $this->formCollection($product->get('categories')); 

我試過這樣

echo "<div>".$this->formLabel($this->get('categories'))."</div>"; 
echo "<div>".$this->formInput($this->get('categories'))."</div>"; 

但它拋出致命錯誤。

Catchable fatal error: Object of class Zend\Form\View\Helper\FormLabel could not be converted to string in /opt/lampp/htdocs/zend2/module/Test/view/test/index/testform.phtml on line 39

我該如何解決這個問題?

回答

0

而不是$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>"; 
+0

謝謝,你可以給我'formLabel'參考? – Hiranya

+0

@Hiranya檢查此鏈接:https://framework.zend.com/manual/2.1/en/modules/zend.form.view.helpers.html#formlabel –

+0

使用上面的ref我試圖做'echo $ this-> formCollection($ product-> get('categories'));',但是我怎樣才能讓它在'collection'中分開? – Hiranya

相關問題