2012-12-31 4 views
1

현재 CakePHP를 사용 중입니다. 데이터베이스에 데이터를 제출하지 않는 양식에 문제가 있습니다. 오류 메시지가없고 디버깅 할 때 양식 데이터가 배열에 추가 된 것 같습니다 (첨부 된 이미지 참조). 양식이 데이터를 제출하지 않습니다.

내 모델 :

:이 컨트롤러의 추가 기능이

<h1>Add New Case</h1> 

<?php 
pr($this->request->data); 
echo $this->Form->create('Split'); 
echo $this->Form->input('title'); 
echo $this->Form->input('url'); 
echo $this->Form->input('descr', array('rows' => '2')); 
echo $this->Form->end('Add New Case'); 
?> 

:

클래스 분할은 AppModel을 확장 {

public $validate = array(
    'title' => array('rule' => 'notEmpty'), 
    'url' => array('rule' => 'notEmpty'), 
    'descr' => array('rule' => 'notEmpty') 
); 

그리고이 내 생각이다

public function add() { 

    if ($this->request->is('split')) { 

     $this->Split->create(); 
     if ($this->Split->save($this->request->data)) { 
      $this->Session->setFlash('Your case has been saved.'); 
      $this->redirect(array('action' => 'index')); 

     } else { 
      $this->Session->setFlash('Unable to add case.'); 
     } 
    } 

} 

Afte 내가 CakePHP는 꽤 새로운 해요

<form action="/uilab/splits/add" id="SplitAddForm" method="post" accept-charset="utf-8"> 

<div style="display:none;"><input type="hidden" name="_method" value="POST"></div> 

<div class="input text required"> 

    <label for="SplitTitle">Title</label> 

    <input name="data[Split][title]" maxlength="255" type="text" value="Some title" id="SplitTitle"></div> 

    <div class="input text required"> 
     <label for="SplitUrl">Url</label> 
     <input name="data[Split][url]" maxlength="255" type="text" value="http://www.someurl.com" id="SplitUrl"> 
    </div> 

    <div class="input textarea required"> 
     <label for="SplitDescr">Descr</label> 
      <textarea name="data[Split][descr]" rows="2" cols="30" id="SplitDescr">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</textarea> 
     </div> 

    <div class="submit"><input type="submit" value="Add New Case"></div> 

</form> 

: R 데이터를 제출 누르면 스플릿 (Split) 배열에 삽입되어 있지만 형태는 제출되지 :

After pressing submit

이 밖으로 렌더링되는 HTML입니다 따라서이 문제를 해결하는 방법에 대한 아이디어는 높이 평가됩니다.

아, 그리고 새해 복 많이 받으세요! :)

답변

2
if ($this->request->is('split')) { 

if ($this->request->is('post')) { 

에 대한 request handling를 참조해야한다.

요청이 결코 split이 아니므로 코드가 실행되지 않습니다. 유효한 값은 post, get, put ...

+0

그랬습니다! 고마워요! :) – timkl

관련 문제