formHelper
时间没有将数据插入数据库:
+---------------------------------------------------+
|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 ; } } }
类AttendencesController扩展了AppController {
public function intime() { if($this->Attendence->add($this->request->data)==true){ $this->redirect(array('action'=>'intime')); } }
}
答案 0 :(得分:1)
关注CakePHP的代码约定:
echo $this->Form->create('Model');
的第一个参数是模型名称,视图与之相关。将您的Employee in Time
替换为您的型号名称:echo $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'));
}
}
}
}