我是CakePHP的新手,我創建簡單的表單來添加/編輯/刪除發佈,因爲它是在其官方網站上解釋,我的問題,同時添加發布到數據庫它不是保存數據,它正在創建空白項數據庫cakephp save()創建空白條目到數據庫
這裏是代碼Postscontroller.php
<?php
class PostsController extends AppController {
public $helpers = array('Html', 'Form');
public $components = array('Session');
public function add() {
if ($this->request->is('post')) {
$this->Post->create();
if ($this->Post->save($this->request->data)) {
$this->Session->setFlash(__('Your post has been saved.'));
return $this->redirect(array('action' => 'index'));
}
//debug($this->Post->validationErrors);
$this->Session->setFlash(__('Unable to add your post.'));
}
}
}
?>
這裏是代碼型號post.php中:
<?php
class Post extends AppModel {
public $validate = array(
'title' => array(
'rule' => 'notEmpty'
),
'body' => array(
'rule' => 'notEmpty'
)
);
}
?>
這裏是查看添加代碼。C tp:
<h1>Add Post</h1>
<?php
echo $this->Form->create('post');
echo $this->Form->input('title');
echo $this->Form->input('body');
echo $this->Form->end('Save Post');
?>
任何人都可以建議我是什麼導致數據庫的空白條目?
你可以試試這個:調試($這個 - >請求 - >數據)? – deadman 2014-09-30 10:33:35