【发布时间】:2014-09-30 19:03:13
【问题描述】:
我是 CakePHP 的新手,我正在创建简单的表单来添加/编辑/删除帖子,正如它在其官方网站上解释的那样,我的问题,在将帖子添加到数据库时它不保存数据,它正在创建空白条目数据库
这是 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'
)
);
}
?>
这是查看 add.ctp 的代码:
<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');
?>
谁能建议我是什么导致数据库出现空白条目?
【问题讨论】:
-
你可以试试这个:debug($this->request->data) ??
标签: php cakephp cakephp-model