Book Image

Phalcon Cookbook

By : Serghei Iakovlev, David Schissler
1 (2)
Book Image

Phalcon Cookbook

1 (2)
By: Serghei Iakovlev, David Schissler

Overview of this book

Phalcon is a high-performance PHP framework delivered as a PHP extension. This provides new opportunities for speed and application design, which until recently have been unrealized in the PHP ecosystem. Packed with simple learning exercises, technology prototypes, and real-world usable code, this book will guide you from the beginner and setup stage all the way to advanced usage. You will learn how to avoid niche pitfalls, how to use the command-line developer tools, how to integrate with new web standards, as well as how to set up and customize the MVC application structure. You will see how Phalcon can be used to quickly set up a single file web application as well as a complex multi-module application suitable for long-term projects. Some of the recipes focus on abstract concepts that are vital to get a deep comprehension of Phalcon and others are designed as a vehicle to deliver real-world usable classes and code snippets to solve advanced problems. You’ll start out with basic setup and application structure and then move onto the Phalcon MVC and routing implementation, the power of the ORM and Phalcon Query Language, and Phalcon’s own Volt templating system. Finally, you will move on to caching, security, and optimization.
Table of Contents (17 chapters)
Phalcon Cookbook
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface
Index

Using the query builder for complex yet fluent model querying


Phalcon has a powerful query builder that can generate queries without writing PHQL or SQL. This is accomplished by creating a Phalcon\Mvc\Model\Query\Builder object and then chaining a series of methods together to generate a Phalcon\Mvc\Model\Query. This technique also has an advantage of having IDE support through the Developer Tools integration.

Getting ready

This recipe uses the chapter_04 database that we set up in the chapter introduction and the Phalcon Developer Tools which we will use to set up a project skeleton.

How to do it…

Follow these steps to complete this recipe:

  1. We need to have an application skeleton for experimentation. If you already have such an application, you can skip this step. Create a project skeleton using the simple template:

    phalcon project query_builder simple
  2. Now point the web browser at the root directory of the project. There should be a page with Congratulations! ..... If we see the Volt directory...