cakephp save () создает пустую запись в базе данных

Я новичок в 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');
?>

Может кто-нибудь предложить мне, что вызывает пустые записи в базе данных?

0

Решение

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

Другие решения

В config/core.php файл изменить debug label to 2,(Configure::write('debug', 2)) и попробуйте сохранить снова. Название модели должно быть Post в форме. Пожалуйста, проверьте почтовые данные перед сохранением.

debug($this->request->data);

exit;
0

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector