phalcon php framework documentation

Download Phalcon Php Framework Documentation

Post on 01-Nov-2014

867 views

Category:

Documents

8 download

Embed Size (px)

TRANSCRIPT

Phalcon PHP Framework DocumentationRelease 0.9.0

Phalcon Team

February 07, 2013

Contents

1 2

What is Phalcon? Table of Contents 2.1 Our motivation . . . . . . . . . . . . . . 2.2 Framework Benchmarks . . . . . . . . . 2.3 Installation . . . . . . . . . . . . . . . . 2.4 Tutorial 1: Lets learn by example . . . . 2.5 Tutorial 2: Explaining INVO . . . . . . . 2.6 Tutorial 3: Creating a Simple REST API 2.7 Using Dependency Injection . . . . . . . 2.8 The MVC Architecture . . . . . . . . . . 2.9 Using Controllers . . . . . . . . . . . . . 2.10 Working with Models . . . . . . . . . . 2.11 Phalcon Query Language (PHQL) . . . . 2.12 ODM (Object-Document Mapper) . . . . 2.13 Using Views . . . . . . . . . . . . . . . 2.14 View Helpers . . . . . . . . . . . . . . . 2.15 Volt: Template Engine . . . . . . . . . . 2.16 MVC Applications . . . . . . . . . . . . 2.17 Routing . . . . . . . . . . . . . . . . . . 2.18 Dispatching Controllers . . . . . . . . . 2.19 Micro Applications . . . . . . . . . . . . 2.20 Working with Namespaces . . . . . . . . 2.21 Events Manager . . . . . . . . . . . . . 2.22 Request Environment . . . . . . . . . . 2.23 Returning Responses . . . . . . . . . . . 2.24 Generating URLs and Paths . . . . . . . 2.25 Flashing Messages . . . . . . . . . . . . 2.26 Storing data in Session . . . . . . . . . . 2.27 Filtering and Sanitizing . . . . . . . . . 2.28 Contextual Escaping . . . . . . . . . . . 2.29 Reading Congurations . . . . . . . . . 2.30 Data Pagination . . . . . . . . . . . . .

3 5 5 6 22 35 45 62 70 86 87 94 143 154 166 180 189 206 213 226 230 238 239 245 247 250 253 255 258 262 265 267

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

i

2.31 2.32 2.33 2.34 2.35 2.36 2.37 2.38 2.39 2.40 2.41 2.42 2.43 2.44 2.45 3

Improving Performance with Cache Security . . . . . . . . . . . . . . . Access Control Lists ACL . . . . . Multi-lingual Support . . . . . . . Universal Class Loader . . . . . . . Logging . . . . . . . . . . . . . . . Annotations Parser . . . . . . . . . Command Line Applications . . . . Database Abstraction Layer . . . . Internationalization . . . . . . . . . Database Migrations . . . . . . . . Debugging Applications . . . . . . Phalcon Developer Tools . . . . . . API Indice . . . . . . . . . . . . . License . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

269 275 277 280 283 287 290 295 295 306 307 313 318 340 629 631

Other formats

ii

Phalcon PHP Framework Documentation, Release 0.9.0

Welcome to Phalcon framework, a new approach on PHP frameworks. Our mission is to give you an advanced tool for developing web sites and applications without worrying about performance.

Contents

1

Phalcon PHP Framework Documentation, Release 0.9.0

2

Contents

CHAPTER 1

What is Phalcon?

Phalcon is an open source, full stack framework for PHP 5 written as a C-extension, optimized for high performance. You dont need learn or use the C language, since the functionality is exposed as PHP classes ready for you to use. Phalcon also is loosely coupled, allowing you to use its objects as glue components based on the needs of your application. Phalcon is not only about performance, our goal is to make it robust and easy to use!

3

Phalcon PHP Framework Documentation, Release 0.9.0

4

Chapter 1. What is Phalcon?

CHAPTER 2

Table of Contents

2.1 Our motivationThere are many PHP frameworks nowadays, but none of them is like Phalcon (Really, trust us on this one). Almost all programmers prefer to use a framework. This is primarily because it provides a lot of functionality that is already tested and ready to use, therefore keeping code DRY (Dont Repeat Yourself). However, the framework itself demands a lot of le inclusions and hundreds of lines of code to be interpreted and executed on each request from the actual application. This operation slows the application down and subsequently impacts the end user experience.

2.1.1 The QuestionWhy cant we have a framework with all of its advantages but with none or very few disadvantages? This is why Phalcon was born! During the last few months, we have extensively researched PHPs behavior, investigating areas for signicant optimizations (big or small). Through understanding of the Zend Engine, we managed to remove unnecessary validations, compacted code, performed optimizations and generated low-level solutions so as to achieve maximum performance from Phalcon.

2.1.2 Why? The use of frameworks has become mandatory in professional development with PHP Frameworks offer a structured philosophy to easily maintain projects writing less code and making work more fun

2.1.3 Inner workings of PHP? PHP has dynamic and weak variable types. Every time a binary operation is made (ex. 2 + 2), PHP checks the operand types to perform potential conversions PHP is interpreted and not compiled. The major disadvantage is performance loss Every time a script is requested it must be rst interpreted.

5

Phalcon PHP Framework Documentation, Release 0.9.0

If a bytecode cache (like APC) isnt used, syntax checking is performed every time for every le in the request

2.1.4 How traditional PHP frameworks work? Many les with classes and functions are read on every request made. Disk reading is expensive in terms of performance, especially when the le structure includes deep folders Modern frameworks use lazy loading (autoload) to increase performance (for load and execute only the code needed) Continuous loading or interpreting is expensive and impacts performance The framework code does not change very often, therefore an application needs to load and interpret it every time a request is made

2.1.5 How does a PHP C-extension work? C extensions are loaded together with PHP one time on the web servers daemon start process Classes and functions provided by the extension are ready to use for any application The code isnt interpreted because is already compiled to a specic platform and processor

2.1.6 How does Phalcon work? Components are loosely coupled. With Phalcon, nothing is imposed on you: youre free to use the full framework, or just some parts of it as a glue components. Low-level optimizations provides the lowest overhead for MVC-based applications Interact with databases with maximum performance by using a C-language ORM for PH