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

Understanding the default routing strategy for controllers


One of the most essential parts of any web framework is having a flexible way of converting browser URLs into a definable logic path on the server, and with Phalcon this is achieved with the Phalcon\Mvc\Router class. To start with, it is necessary to have an understanding of the default routing strategy and then later, this can be expanded upon.

The default routing strategy can be described simply in that each web request is assigned to a Phalcon\Mvc\Controller class and then to the specific action function within that controller. So with each URL, we can begin to think about which PHP controller class the request will be directed to and then which action method within that controller will finally handle the request. In this way, groups of common behavior can be grouped together into a single controller for both reducing duplicate code and for organization. The best part is that right from the start, each new action function is automatically...