cakephp 2.3格式时间输入时分秒

cakephp 2.3格式时间输入时分秒,cakephp,Cakephp,我正在尝试格式化输入,但没有成功。我需要将mp3和每个音频文件的持续时间一起保存到我的表中。为此,我希望有一个输入,允许我选择小时:分钟:秒。表中持续时间的字段是TIME,我想不需要dateTime 以下是我所做的不起作用的事情: <?php echo $this->Form->input('duration', array('type' => 'time', 'label' => 'Durée piste', 'dateFormat' => 'H:i:s')

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

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

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

有人知道怎么做吗?
提前谢谢

如果您不是php专家,那么您可以使用下面给出的简单代码

注意:Post是我的型号名称。请用您的替换。

在控制器中添加函数

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));
$hours=array();
对于($i=0;$iinput('hours',数组('type'=>'select','options'=>$hours));
echo$this->Form->input('minutes',array('type'=>'select','options'=>$ms));
echo$this->Form->input('seconds',array('type'=>'select','options'=>$ms));

如果您不是php专家,那么您可以使用下面给出的简单代码

注意:Post是我的型号名称。请用您的替换。

在控制器中添加函数

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));
$hours=array();
对于($i=0;$iinput('hours',数组('type'=>'select','options'=>$hours));
echo$this->Form->input('minutes',array('type'=>'select','options'=>$ms));
echo$this->Form->input('seconds',array('type'=>'select','options'=>$ms));

只要用这些新阵列替换旧阵列即可

$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;
    }
}
$hours=array();
对于($a=0;$a<2;$a++){
对于($b=0;$b<10;$b++){
如果($a.$b==13){
打破
}
$hours[$a.$b]=$a.$b;
}
}
$ms=array();
对于($a=0;$a<6;$a++){
对于($b=0;$b<10;$b++){
$ms[$a.$b]=$a.$b;
}
}

只要用这些新阵列替换旧阵列即可

$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;
    }
}
$hours=array();
对于($a=0;$a<2;$a++){
对于($b=0;$b<10;$b++){
如果($a.$b==13){
打破
}
$hours[$a.$b]=$a.$b;
}
}
$ms=array();
对于($a=0;$a<6;$a++){
对于($b=0;$b<10;$b++){
$ms[$a.$b]=$a.$b;
}
}

有一个开放的PR允许秒数。到目前为止,您必须编写自己的方法或使用一组输入进行模拟。请参阅:谢谢Mark,我检查了它,不幸的是我不理解我读到的内容:)。我不是php专家:(有一个开放的PR允许秒。到目前为止,您必须编写自己的方法或使用一组输入进行模拟。请参阅:谢谢Mark,我检查了它,不幸的是我不理解我读到的内容:)。我不是php专家:(非常感谢ketan patel!一切正常,我甚至在单打时添加了一些0,看起来像这样:01:07:33非常感谢ketan patel!一切正常,我甚至在单打时添加了一些0,看起来像这样:01:07:33