如果您不是 php 专家,那么您可以使用下面给出的简单代码。
注意:帖子是我的模型名称。所以用你的替换它。
在控制器中添加功能
public function add() {
if ($this->request->is('post')) {
$this->Post->create();
$hours = $this->data['Post']['hours'];
$minutes = $this->data['Post']['minutes'];
$seconds = $this->data['Post']['seconds'];
$this->request->data['Post']['duration']=$hours.':'.$minutes.':'.$seconds;
if ($this->Post->save($this->request->data)) {
$this->Session->setFlash('Your post has been saved.');
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash('Unable to add your post.');
}
}
}
add.ctp 文件中的代码
$hours=array();
for($i=0;$i<13;$i++){
$hours[$i]=$i;
}
$ms=array();
for($i=0;$i<60;$i++){
$ms[$i]=$i;
}
echo $this->Form->input('hours',array('type' => 'select', 'options' => $hours));
echo $this->Form->input('minutes',array('type' => 'select', 'options' => $ms));
echo $this->Form->input('seconds',array('type' => 'select', 'options' => $ms));