Book Image

Learning Phalcon PHP

By : Calin Rada, Ioan C Rada
Book Image

Learning Phalcon PHP

By: Calin Rada, Ioan C Rada

Overview of this book

Table of Contents (17 chapters)
Learning Phalcon PHP
About the Author
About the Reviewers


Phalcon is the fastest PHP framework out there, and it is delivered as a C extension. More than that, you will find it very easy to learn. This book will present in detail the most common and useful parts of Phalcon PHP, as well as guide you to lean towards making the right decision when developing a Phalcon-driven application.

Learning Phalcon PHP is an interesting journey that starts with guides for installing the required software and preparing the working environment and project structure, and continues with a step-by-step approach development of each module.

By the end of this book, you will have developed a simple but fully functional news website and gained advanced knowledge on how Phalcon works.

What this book covers

Chapter 1, Getting Started with Phalcon, introduces the Phalcon Framework. In this chapter, you learn how to install and configure Phalcon.

Chapter 2, Setting Up the MVC Structure and the Environment for Our Project, helps you get to grips with the basics of MVC (Model-View-Controller) and setting up the work environment.

Chapter 3, Learning Phalcon's ORM and ODM, is about Phalcon's ORM (Object-relational Mapping) and ODM (Object-Document Mapper). You learn how to connect to a database and create models and relations between them.

Chapter 4, Database Architecture, Models, and CLI Applications, teaches you how to create the database architecture and the models needed for our project. You also learn about Phalcon CLI and develop a simple CLI application.

Chapter 5, The API Module, helps you start the development of a RESTful API module.

Chapter 6, Assets, Authentication, and ACL, explains assets management (JavaScript files, style sheets, and images), and you create a simple authentication system based on an ACL (access control list).

Chapter 7, The Backoffice Module (Part 1), shows you how to develop CRUD operations. This first part is about CRUD for categories and hashtags.

Chapter 8, The Backoffice Module (Part 2), is a continuation of the previous chapter. Here, you develop CRUD operations for users and articles.

Chapter 9, The Frontend Module, helps you develop the frontend template. You learn how to implement Elasticsearch and Mongo to improve the speed of your application.

Chapter 10, Going Further, teaches you common operations, such as file uploads and annotations.

What you need for this book

The most important thing that you need is some knowledge of PHP 5.3 or later and Linux environments (this book is written based on Ubuntu/Debian). If you are not using a Linux distribution, or you are using a distribution other than Ubuntu/Debian, you will need to look up their official documentation to install the required software.

Who this book is for

If you are an intermediate PHP developer with some basic knowledge of installing and configuring your environment, then this book is for you. Familiarity with PHP frameworks will make your life easier.


In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "Deleting data is easier, since we don't need to do more than calling the built-in delete() method."

A block of code is set as follows:

$di['session'] = function () {
  $session = new Phalcon\Session\Adapter\Files();
  return $session;

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

public function registerServices(\Phalcon\DiInterface $di) {
  $config = include __DIR__ . "/Config/config.php";
  $di['config'] = $config;
  include __DIR__ . "/Config/services.php";

Any command-line input or output is written as follows:

$ cd modules/Frontend/Views/Default
$ mkdir index
$ cd index
$ touch index.volt

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Going back to the article list, you will see the new title, and the Updated column will have a new value."


Warnings or important notes appear in a box like this.


Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.


Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from


Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.


You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.