Book Image

Getting Started with Phalcon

By : Stephan A. Miller
Book Image

Getting Started with Phalcon

By: Stephan A. Miller

Overview of this book

<p>Phalcon is an open source PHP framework which makes developing with PHP easier and more efficient by combining the speed and performance of C with the unique development features of the MVC architecture. Phalcon is installed as a PHP module so you don’t have to download an archive like you do with other frameworks, and building projects is made easier with its controllers and models. The Phalcon Query Language (PHQL) makes this tool even more expressive and clean. Its reputation as the most downloaded PHP tool is definitely justified by its rich offerings. This tutorial provides you with the knowledge you need to build your very own web application with the revolutionary Phalcon framework. This comprehensive guide will start by describing the installation of Phalcon PHP. You will then learn how to build projects and how to further utilize the Phalcon Developer Tools to build models, views, and controllers with the central example of a blog application. Features like PHQL are also explained and implemented effectively throughout the book. The genius in you will be revered by the stunning web application that you will be able to create by reading this book. This handy guide gives you a detailed introduction to using the remarkable Phalcon framework to develop web applications. You will begin by learning how to install the Phalcon module and how to build your own projects. The blog application is the central example throughout the book, and by using Phalcon Developer Tools and web tools, you will create and optimize the basic skeleton for your application with ease and efficiency. You will learn how to add rich features to your blog using Phalcon Views, Models, and Controllers. You will also gain expertise in Phalcon functionalities like the Volt template engine, view helpers, PHQL, and so on. This is an invaluable tutorial for enthusiasts and developers alike who wish to use the fascinating Phalcon PHP framework to rapidly design and develop impressive web applications.</p>
Table of Contents (12 chapters)
Getting Started with Phalcon
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 Timestampable(
            array(
                'beforeUpdate' => array(
                    'field' =...