I started to use CakePHP3.0 by mere curiosity. To familiarize myself with the new features of CakePHP3.0, I followed the blog tutorial in official website(http://book.cakephp.org/3.0/en/tutorials-and-examples/blog/blog.html). What I did was just simply copy and past of the source code there. Everything works fine, EXCEPT FOR fields "created" and "modified" not being saved. They just stay NULL. I have confirmed that this feature works fine in CakePHP 2.4.6. Below is the table definition and function add() for the blog tutorial.
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(50),
body TEXT,
created DATETIME DEFAULT NULL,
modified DATETIME DEFAULT NULL
);
public function add(){
$article = $this->Articles->newEntity($this->request->data);
if($this->request->is("post")){
if($this->Articles->save($article)){
$this->Session->setFlash("Success!");
return $this->redirect(["action"=>"index"]);
}
$this->Session->setFlash("Fail!");
}
$this->set(compact("article"));
}
You need to add the TimestampBehavior in 3.0.
https://github.com/cakephp/cakephp/blob/3.0/src/Model/Behavior/TimestampBehavior.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With