2011-11-19 5 views
0

그래서 CakePHP로 양식을 저장하려고합니다. 아주 간단한 형식이지만, 어떤 이유로 INSERT 문이 생성되지 않습니다. 여기 CakePHP 2.0 저장 안함

는 컨트롤러에서 조각입니다 : 데이터베이스 여기

<?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')); ?> 

된다 : 여기

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

뷰입니다 : 여기

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); 
} 

나의 모델이다

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이 배열 $ this-> 요청 -> 데이터를 보여줍니다? –

답변

1

양식을 올바르게 작성하지 않은 것처럼 보입니다. 'DATE'을 (를) 만들려고합니다. '날짜'이어야합니다. 이에게 이동 보내기

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

내 영웅 야. – Sugitime

+0

Lolz. 힘내 친구 야. –

0

나는 게시물 오래 알고를 여전히 여기에 착륙 사람들을 위해 :

때로는 형식이 자동으로 PUT 요청을 제출하고 $ this-은> 요청 -> '(이다

post ') false를 반환합니다.

올바른 테스트는 다음과 같습니다

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