0

我正在尝试格式化我的输入但没有任何成功。我需要使用每个音频文件的持续时间将 mp3 保存到我的表中。为此,我想要一个允许我选择小时:分钟:秒的输入。我表中持续时间的字段是 TIME,我猜我不需要 dateTime。

所以这是我所做的不起作用的事情:

<?php echo $this->Form->input('duration', array('type' => 'time', 'label' => 'Durée piste', 'dateFormat' => 'H:i:s')); ?>

有谁知道该怎么做?提前致谢!

4

2 回答 2

3

如果您不是 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));
于 2013-08-09T13:11:33.573 回答
0

只需用这些新阵列替换旧阵列。

$hours=array();

for($a=0; $a < 2; $a++){
    for($b=0; $b < 10; $b++){
        if ($a.$b == 13) {
            break;    
        }
        $hours[$a.$b]=$a.$b;

    }
}

$ms=array();

for($a=0; $a < 6; $a++){
    for($b=0; $b < 10; $b++){
        $ms[$a.$b]=$a.$b;
    }
}
于 2013-08-10T04:30:47.323 回答