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

Examining our Posts controller


Now let's open PostsController.php file located at app/controllers in our editor. There is definitely a lot going on in this file. There are seven methods in our PostsController class suffixed with actions. Each of these actions handles requests and creates responses in our application. Each corresponds to a URI in our application: http://localhost/phalconBlog/[model]/[action]. When we browse to http://www.localhost/phalconBlog/posts/, by default, the indexAction function is called.

Let's take a look at each of these actions and modify them if we need to.

Create

Let's take a look at the createAction function, which saves our new blog posts for us.

First, we should learn a little about Phalcon\Mvc\Dispatcher. The dispatcher is another one of the services that was loaded in our Dependency Injection container. The dispatcher takes the request object and instantiates a controller based on the attributes of that object. When a controller is instantiated, it acts as...