CakePHP:FormHelper时间字段没有插入任何数据


CakePHP: FormHelper Timefield not inserting any data

formHelper For time没有将数据插入数据库:

+---------------------------------------------------+
|attendence_id|id   |in_time    |out_time|date.     |
+---------------------------------------------------+
|15           |4    |00:00:30   |00:00:30|2014-04-12|
+---------------------------------------------------+

我的视图

<div class="index">
 <?php
 echo $this->Form->create('Employee In Time');
 echo $this->Form->input('Employee ID',array("name"=>"id"));
 echo $this->Form->input('In Time', array(
     'name' => 'in_time',
     'timeFormat' => '24',
     'type' => 'time',
     'selected' => '09:30:00'
 ));
 echo $this->Form->input('Out Time', array(
     'name' => 'out_time',
     'timeFormat' => '24',
     'type' => 'time',
     'selected' => '09:30:00'
 ));

 echo $this->Form->input('Date Insert in Y/M/D', array(
    'name' => 'date',
    'dateFormat' => 'YMD',
    'minYear' => date('Y') - 70,
    'maxYear' => date('Y') - 18 ));
 echo $this->Form->end('Add');
?>
</div>
<div class="actions">
    <h3>Actions</h3>
    <ul>
        <li><a href="/users/add">New Employee</a></li>
        <li><a href="/user_types">Attendance</a></li>
        <li><a href="/users/add">Salary Calculator</a></li>
        </ul>
</div>

我的模型

class Attendence extends AppModel {

    function add($data){
        if (!empty($data)) {
            $this->create();
            if($this->save($data)) {
                return true ;
            }
        }
    }

我的控制器

class AttendancesController扩展AppController{

public function intime()
{

    if($this->Attendence->add($this->request->data)==true){
        $this->redirect(array('action'=>'intime'));
    }

}

}

请帮助

注意CakePHP的代码约定:

echo $this->Form->create('Model');的第一个参数是型号名称,视图与相关。用型号名称替换Employee in Timeecho $this->Form->create('Attendence');

我建议把你的型号代码放进控制器:

class AttendencesController extends AppController 
{  
    public function intime()
    {
        if($this->request->is('post','put'))
        {
            $this->Attendence->create();
            if($this->Attendence->save($this->request->data))
            {
                $this->redirect(array('action'=>'intime'));
            }
        }     
    }   
}