2011-11-19 65 views
0

所以我试图用CakePHP保存表单。它是一个相当简单的形式,但由于某种原因,INSERT语句永远不会生成。CakePHP 2.0不保存

下面是从控制器片段:

public function add($sid = null) { 
    if($this->request->is('post')) { 
     //The app enters here. debug($this->request->data) confirms the data is there. 
     if($this->Date->save($this->request->data)) { 
      //debug($this->Date->save($this->request->data)) confirms CakePHP thinks its saving the data 
      //however looking at the data, and the MySQL log, an INSERT statement is never attempted. 
      //The flash and redirect occur as expected. 
      $this->Session->setFlash('Dates Saved!'); 
      $this->redirect(array('action' => 'school', $sid)); 
     } 
    } 
    $this->set('schoolid', $sid); 
} 

这里是我的模型:

<?php 
class Date extends AppModel { 
    public $name = 'Date'; 
} 

这里是视图:

<?php 
echo $this->Html->script(array(
          'dhtmlxCalendar/dhtmlxcalendar.js' 
         )); 
echo $this->Html->css(array('dhtmlxCalendar/dhtmlxcalendar.css', 'dhtmlxCalendar/skins/dhtmlxcalendar_dhx_skyblue.css')); 
?> 
<div style="position:relative;height:380px;"> 
<?php echo $this->Form->create('Dates'); ?> 
<?php echo $this->Form->input('schoolid', array('value' => $schoolid, 'type' => 'hidden')); ?> 
<?php echo $this->Form->input('grade', array('options' => array('5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9', '10' => '10', '11' => '11', '12' => '12'))); ?> 
<?php echo $this->Form->input('startreg', array('label' => 'Start Registration Date')); ?> 
<?php echo $this->Form->input('endreg', array('label' => 'End Registration Date')); ?> 
<?php echo $this->Form->input('lottery', array('label' => 'Lottery Date')); ?> 
<?php echo $this->Form->end('Save Dates'); ?> 
</div> 
<?php echo $this->Html->script(array('Schools/add.js')); ?> 

这里是数据库:

CREATE TABLE IF NOT EXISTS `dates` (
    `id` int(10) NOT NULL AUTO_INCREMENT, 
    `schoolid` int(2) NOT NULL, 
    `grade` int(2) NOT NULL, 
    `startreg` datetime NOT NULL, 
    `endreg` datetime NOT NULL, 
    `lottery` datetime NOT NULL, 
    PRIMARY KEY (`id`) 
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; 

如果任何人有任何想法为什么会发生这种情况,或者我可以采取什么样的调试步骤来解决这个问题,我将不胜感激!

+0

显示了这阵$这个 - >请求 - >数据什么的var_dump? –

回答

1

看起来你没有正确创建你的表单。您正试图创建'日期'。它应该是'日期'。这给一展身手:

<?php echo $this->Form->create('Date'); ?> 
+0

老兄你的我的英雄。 – Sugitime

+0

洛尔兹。队友的欢呼声。 –

0

我知道后是旧的,但对于那些谁仍然在此着陆:

有时形式与PUT请求自动提交和$这个 - >请求 - >是(”后')将返回false。

正确的测试将是:

if ($this->request->is('post') || $this->request->is('put')) { ... }