我正在尝试用简单的博客学习蛋糕.我用蛋糕烘烤来制作我的控制器.Post模型有一个created_date字段,但我想在服务器端设置它(客户端可以篡改它).我添加了几行到添加控制器,如下所示:
public function add() {
if ($this->request->is('post')) {
$this->Post->create();
date_default_timezone_set("UTC");
$this->request->data['Post']['created_date'] = date("c"); //set create date server side
if ($this->Post->save($this->request->data)) {
$this->Session->setFlash(__('The post has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The post could not be saved. Please, try again.'));
}
}
$authors = $this->Post->Author->find('list');
$tags = $this->Post->Tag->find('list');
$this->set(compact('authors', 'tags'));
}
Run Code Online (Sandbox Code Playgroud)
问题是创建日期根本没有保存,它设置为0000-00-00.我读到的一切都说这应该是好的.即使我查看debugkit,它也会显示post数据在数组中具有正确的created_date.
cakephp ×1