我创建了一个表单,它有一个循环来显示多行。我使用表单助手在每一行上都有一个选择。它创建的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