我創建了一個表單,它有一個循環來顯示多行。我使用表單助手在每一行上都有一個選擇。它創建的ID是一樣的,有沒有辦法添加一個計數器,或一些定義信息的ID?cakePHP:如何更改表單元素的ID(使用表單助手)?
我使用$this->Form->input('city_id')
來輸出從我的城市模型中選擇的城市。所有ID都是ModelCityId
。我想獲得像ModelCityId1,ModelCityId2
,ModelCityId3
等,這可能嗎?還是有更好的方式去顯示循環中的選項?
感謝您的任何建議。
這裏是代碼的相關部分。
while ($current_date != $departure_date) {
$current_date = date("d-M-y", strtotime($current_date . " +1 day"));
$output .= '<tr>';
$output .= '<td>'.$current_date.'</td>';
// irrelevant other columns
$output .= '<td>'.$this->Form->input('city_id', array('label' => '', 'empty' => true)).'</td>';
$output .= '</tr>';
}
'$ current_date = date(「d-M-y」,strtotime(date(「Y-m-d」,strtotime($ current_date))。「+1 day」));' 這條線讓我感到困惑。 – Dunhamzzz 2011-03-02 09:12:29
可能有更好的方法來做到這一點,但我用它來添加一天到日期字符串(從網站的另一部分,已經格式化)。 - 仔細一看,意識到我過了一會兒就變得複雜了。更改爲'$ current_date = date(「d-M-y」,strtotime($ current_date。「+1 day」));' – 2011-03-02 21:22:55