O'Reilly logo

Getting Started with Phalcon by Stephan Miller

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Phalcon models revisited

Another thing we need to fix in our application is the fact that our dates don't mean anything. We have published and updated dates in our posts table, which we are not using. Let's make sure we're setting those dates. Let's open up the Posts.php file located at app/model. We are going to add more code to the initialize function of our Posts model, and we are going to use a behavior on our date fields. First, add this line of code after the first PHP tag:

use Phalcon\Mvc\Model\Behavior\Timestampable;

Then, add the following lines of code to the initialize function in this model:

 $this->addBehavior(new Timestampable( array( 'beforeCreate' => array( 'field' => 'published', 'format' => 'Y-m-d H:i:s' ) ) )); $this->addBehavior(new ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required