Book Image

Learning Phalcon PHP

Book Image

Learning Phalcon PHP

Overview of this book

Table of Contents (17 chapters)
Learning Phalcon PHP
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

ORM/ODM operations (create, update, delete, transactions, and validations)


Before we continue, let's make our article table a little more complex, by adding a few columns. We will add three more columns: is_published, created_at, and updated_at.

The is_published field will be a Boolean type (in MySQL, it will have a value of 0 or 1), and the created_at and updated_at fields will have the datetime type. They will hold information about when our article was created and when it was updated. You can alter the article table and add these fields using the following code:

ALTER TABLE `article` ADD `is_published` BOOLEAN NOT NULL DEFAULT FALSE ,
ADD `created_at` DATETIME NOT NULL ,
ADD `updated_at` DATETIME NULL DEFAULT NULL ;

We also need to make modifications to our Article model and add the getters and setters for these new fields. Open the modules/Core/Models/Article.php file and add the following content:

    protected $is_published;
    protected $created_at;
    protected $updated_at;

   ...