0

私が知りたいのは、2 つの部分からなる質問です。

検証で何も行われないのはなぜですか? また、データがデータベースに投稿されないのはなぜですか?

QuestionsController.php

public function index() {
    $this->set('questions', $this->Question->find('all'));
}

public function view($id = null) {
    $this->Question->id = $id;
    $this->set('question', $this->Question->read());

}

public function ask() {

    if ($this->request->is('post')) {
        if ($this->Question->save($this->request->data)) {
            $this->Session->setFlash('Your Question has been asked.');
            $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash('Unable to ask your question.');
        }
    }
}
}
  ?>

質問モデル

 class Question extends AppModel {

   public $validate = array(
    'question' => array(
        'rule' => 'notEmpty'
    ),
);
}

テーブル postgreSQL

CREATE TABLE questions (
id serial not null unique primary key,
question varchar(245),
timecreated timestamp default CURRENT_TIMESTAMP

)

ask.ctp

<?php
 echo $this->Form->create('Post');
 echo $this->Form->input('question');
 echo $this->Form->end('Ask');
?>
4

1 に答える 1

3

問題は、フォームの作成時に間違ったモデルを指定したことである可能性があります。次の行

echo $this->Form->create('Post');

する必要があります

echo $this->Form->create('Question');
于 2012-05-18T14:20:53.397 に答える