[英]How to edit the html attribute selected in zend form?
因此,我正在開發一個zend應用程序版本1。
我有自己的自定義表單,它會生成html:
<select name="location" id="location" class="span6">
<option value="1" label="B1">B1</option>
<option value="2" label="B2">B2</option>
<option value="3" label="B3">B3</option>
<option value="4" label="B4">B4</option>
<option value="5" label="B5">B5</option>
<option value="6" label="B6">B6</option>
<option value="7" label="B7">B7</option>
<option value="8" label="B8">B8</option>
<option value="9" label="B9">B9</option>
<option value="10" label="B10">B10</option>
</select>
當我在提交后在我的控制器中檢索ID時,我只得到該值的數據:
即我檢索1或2或3而不是B1或B2,依此類推。
$request->getParam("location");
我如何編輯zend在選擇表單中選擇的屬性? 或者如何用我的值填充下拉列表?
這就是我創建下拉菜單的方式:
$formSell->location->addMultiOptions($config->location->toArray());
一些幫助會很好:)謝謝
addMultiOptions()接受一個數組,並將其數組偏移量用作選項值,並將數組值用作選項的顯示名稱。
要獲得所需的內容,您只需要調整數組即可。 考慮以下;
$arrOutput = array();
$arrRawData = $config->location->toArray();
foreach( $arrRawData as $row ) {
$arrOutput[$row] = $row;
}
$formSell->location->addMultiOptions($arrOutput);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.