嗨我被困在这里,任何直接的帮助都将受到赞赏。我正在尝试使用cakephp 1.3中创建的功能,以便自动插入“问题”日期。 DB中字段的名称为“created”,数据类型:date和Default设置为NULL。 使用以下步骤将条目插入表中。
1)此步骤调用Askquestion模型中定义的ask_question函数。
$question['Askquestion']['user_id']=$user_id;
$question['Askquestion']['subject_id']=$_POST['subject_id'];
$question['Askquestion']['topic_id']=$_POST['topic_id'];
$question['Askquestion']['subject']=$_POST['subject_name'];
$question['Askquestion']['topic']=$_POST['topic_name'];
$question['Askquestion']['question']=$_POST['content'];
App::import("model","Askquestion");
$this->Askquestion = new Askquestion();
$this->Askquestion->ask_question($question);
2)在Model
中的ask_question函数中 function ask_question($ data = array()){
$分贝= $这 - >了getDataSource();
$askquestion['Askquestion']['user_id']=$data['Askquestion']['user_id'];
$askquestion['Askquestion']['subject_id']=$data['Askquestion']['subject_id'];
$askquestion['Askquestion']['topic_id']=$data['Askquestion']['topic_id'];
$askquestion['Askquestion']['subject']=$data['Askquestion']['subject'];
$askquestion['Askquestion']['topic']=$data['Askquestion']['topic'];
$askquestion['Askquestion']['question']=$data['Askquestion']['question'];
$this->create();
$this->save($askquestion);
return $this->getLastInsertId();
}
当我检查数据库时,所有其他字段都有相应的值,但是创建的字段中包含NULL。
答案 0 :(得分:0)
我认为类型需要是datetime,而不是date:http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Models.html#created-and-modified。