# 緩存對象關系映射(Caching in the ORM)
# 緩存對象關系映射(Caching in the ORM)
現實中的每個應用都不同,一些應用的模型數據經常改變而另一些模型的數據幾乎不同。訪問數據庫在很多時候對我們應用的來說是個瓶頸。這是由于我們每次訪問應用時都會和數據庫數據通信,和數據庫進行通信的代價是很大的。因此在必要時我們可以通過增加緩存層來獲取更高的性能。本章內容的重點即是探討實施緩存來提高性能的可行性。Phalcon框架給我們提供了靈活的緩存技術來實現我們的應用緩存。
### 緩存結果集(Caching Resultsets)
一個非常可行的方案是我們可以為那些不經常改變且經常訪問的數據庫數據進行緩存,比如把他們放入內存,這樣可以加快程序的執行速度。
當:doc:Phalcon\\Mvc\\Model <../api/Phalcon\_Mvc\_Model> 需要使用緩存數據的服務時Model可以直接從DI中取得此緩存服務modelsCache(慣例名).
Phalcon提供了一個組件(服務)可以用來:doc:\[`](#)緩存 <cache>`任何種類的數據,下面我們會解釋如何在model使用它。第一步我們要在啟動文件注冊這個服務:
```
<pre class="calibre14">```
<?php
use Phalcon\Cache\Frontend\Data as FrontendData;
use Phalcon\Cache\Backend\Memcache as BackendMemcache;
// 設置模型緩存服務
$di->set('modelsCache', function () {
// 默認緩存時間為一天
$frontCache = new FrontendData(
array(
"lifetime" => 86400
)
);
// Memcached連接配置 這里使用的是Memcache適配器
$cache = new BackendMemcache(
$frontCache,
array(
"host" => "localhost",
"port" => "11211"
)
);
return $cache;
});
```
```
在注冊緩存服務時我們可以按照我們的所需進行配置。一旦完成正確的緩存設置之后,我們可以按如下的方式緩存查詢的結果了:
```
<pre class="calibre14">```
<?php
// 直接取Products模型里的數據(未緩存)
$products = Products::find();
// 緩存查詢結果.緩存時間為默認1天。
$products = Products::find(
array(
"cache" => array(
"key" => "my-cache"
)
)
);
// 緩存查詢結果時間為300秒
$products = Products::find(
array(
"cache" => array(
"key" => "my-cache",
"lifetime" => 300
)
)
);
// 使用自定義緩存
$products = Products::find(
array(
"cache" => $myCache
)
);
這里我們也可以緩存關聯表的數據:
```
```
```
<pre class="calibre14">```
<?php
// Query some post
$post = Post::findFirst();
// Get comments related to a post, also cache it
$comments = $post->getComments(
array(
"cache" => array(
"key" => "my-key"
)
)
);
// Get comments related to a post, setting lifetime
$comments = $post->getComments(
array(
"cache" => array(
"key" => "my-key",
"lifetime" => 3600
)
)
);
```
```
如果想刪除已經緩存的結果,則只需要使用前面指定的緩存的鍵值進行刪除即可。
注意并不是所有的結果都必須緩存下來。那些經常改變的數據就不應該被緩存,這樣做只會影響應用的性能。另外對于那些特別大的不易變的數據集,開發者應用根據實際情況進行選擇是否進行緩存。
### 重寫 find 與 findFirst 方法(Overriding find/findFirst)
從上面的我們可以看到這兩個方法是從:doc:Phalcon\\Mvc\\Model繼承而來 <../api/Phalcon\_Mvc\_Model>:
```
<pre class="calibre14">```
<?php
use Phalcon\Mvc\Model;
class Robots extends Model
{
public static function find($parameters = null)
{
return parent::find($parameters);
}
public static function findFirst($parameters = null)
{
return parent::findFirst($parameters);
}
}
```
```
這樣做會影響到所有此類的對象對這兩個函數的調用,我們可以在其中添加一個緩存層,如果未有其它緩存的話(比如modelsCache)。例如,一個基本的緩存實現是我們在此類中添加一個靜態的變量以避免在同一請求中多次查詢數據庫:
```
<pre class="calibre14">```
<?php
use Phalcon\Mvc\Model;
class Robots extends Model
{
protected static $_cache = array();
/**
* Implement a method that returns a string key based
* on the query parameters
*/
protected static function _createKey($parameters)
{
$uniqueKey = array();
foreach ($parameters as $key => $value) {
if (is_scalar($value)) {
$uniqueKey[] = $key . ':' . $value;
} else {
if (is_array($value)) {
$uniqueKey[] = $key . ':[' . self::_createKey($value) .']';
}
}
}
return join(',', $uniqueKey);
}
public static function find($parameters = null)
{
// Create an unique key based on the parameters
$key = self::_createKey($parameters);
if (!isset(self::$_cache[$key])) {
// Store the result in the memory cache
self::$_cache[$key] = parent::find($parameters);
}
// Return the result in the cache
return self::$_cache[$key];
}
public static function findFirst($parameters = null)
{
// ...
}
}
```
```
訪問數據要遠比計算key值慢的多,我們在這里定義自己需要的key生成方式。注意好的鍵可以避免沖突,這樣就可以依據不同的key值取得不同的緩存結果。
上面的例子中我們把緩存放在了內存中,這做為第一級的緩存。當然我們也可以在第一層緩存的基本上實現第二層的緩存比如使用APC/XCache或是使用NoSQL數據庫(如MongoDB等):
```
<pre class="calibre14">```
<?php
public static function find($parameters = null)
{
// Create an unique key based on the parameters
$key = self::_createKey($parameters);
if (!isset(self::$_cache[$key])) {
// We're using APC as second cache
if (apc_exists($key)) {
$data = apc_fetch($key);
// Store the result in the memory cache
self::$_cache[$key] = $data;
return $data;
}
// There are no memory or apc cache
$data = parent::find($parameters);
// Store the result in the memory cache
self::$_cache[$key] = $data;
// Store the result in APC
apc_store($key, $data);
return $data;
}
// Return the result in the cache
return self::$_cache[$key];
}
```
```
這樣我們可以對可模型的緩存進行完全的控制,如果多個模型需要進行如此緩存可以建立一個基礎類:
```
<pre class="calibre14">```
<?php
use Phalcon\Mvc\Model;
class CacheableModel extends Model
{
protected static function _createKey($parameters)
{
// ... Create a cache key based on the parameters
}
public static function find($parameters = null)
{
// ... Custom caching strategy
}
public static function findFirst($parameters = null)
{
// ... Custom caching strategy
}
}
```
```
然后把這個類作為其它緩存類的基類:
```
<pre class="calibre14">```
<?php
class Robots extends CacheableModel
{
}
```
```
### 強制緩存(Forcing Cache)
前面的例子中我們在Phalcon\\Mvc\\Model中使用框架內建的緩存組件。為實現強制緩存我們傳遞了cache作為參數:
```
<pre class="calibre14">```
<?php
// 緩存查詢結果5分鐘
$products = Products::find(
array(
"cache" => array(
"key" => "my-cache",
"lifetime" => 300
)
)
);
```
```
為了自由的對特定的查詢結果進行緩存我們,比如我們想對模型中的所有查詢結果進行緩存我們可以重寫find/findFirst方法:
```
<pre class="calibre14">```
<?php
use Phalcon\Mvc\Model;
class Robots extends Model
{
protected static function _createKey($parameters)
{
// ... Create a cache key based on the parameters
}
public static function find($parameters = null)
{
// Convert the parameters to an array
if (!is_array($parameters)) {
$parameters = array($parameters);
}
// Check if a cache key wasn't passed
// and create the cache parameters
if (!isset($parameters['cache'])) {
$parameters['cache'] = array(
"key" => self::_createKey($parameters),
"lifetime" => 300
);
}
return parent::find($parameters);
}
public static function findFirst($parameters = null)
{
// ...
}
}
```
```
### 緩存 PHQL 查詢(Caching PHQL Queries)
ORM中的所有查詢,不管多么高級的查詢方法內部使用使用PHQL進行實現的。這個語言可以讓我們非常自由的創建各種查詢,當然這些查詢也可以被緩存:
```
<pre class="calibre14">```
<?php
$phql = "SELECT * FROM Cars WHERE name = :name:";
$query = $this->modelsManager->createQuery($phql);
$query->cache(
array(
"key" => "cars-by-name",
"lifetime" => 300
)
);
$cars = $query->execute(
array(
'name' => 'Audi'
)
);
```
```
如果不想使用隱式的緩存盡管使用你想用的緩存方式:
```
<pre class="calibre14">```
<?php
$phql = "SELECT * FROM Cars WHERE name = :name:";
$cars = $this->modelsManager->executeQuery(
$phql,
array(
'name' => 'Audi'
)
);
apc_store('my-cars', $cars);
```
```
### 可重用的相關記錄(Reusable Related Records)
一些模型有關聯的數據表我們直接使用關聯的數據:
```
<pre class="calibre14">```
<?php
// Get some invoice
$invoice = Invoices::findFirst();
// Get the customer related to the invoice
$customer = $invoice->customer;
// Print his/her name
echo $customer->name, "\n";
```
```
這個例子非常簡單,依據查詢到的訂單信息取得用戶信息之后再取得用戶名。下面的情景也是如何:我們查詢了一些訂單的信息,然后取得這些訂單相關聯用戶的信息,之后取得用戶名:
```
<pre class="calibre14">```
<?php
// Get a set of invoices
// SELECT * FROM invoices;
foreach (Invoices::find() as $invoice) {
// Get the customer related to the invoice
// SELECT * FROM customers WHERE id = ?;
$customer = $invoice->customer;
// Print his/her name
echo $customer->name, "\n";
}
```
```
每個客戶可能會有一個或多個帳單,這就意味著客戶對象沒必須取多次。為了避免一次次的重復取客戶信息,我們這里設置關系為reusable為true,這樣ORM即知可以重復使用客戶信息:
```
<pre class="calibre14">```
<?php
use Phalcon\Mvc\Model;
class Invoices extends Model
{
public function initialize()
{
$this->belongsTo(
"customers_id",
"Customer",
"id",
array(
'reusable' => true
)
);
}
}
```
```
此Cache存在于內存中,這意味著當請示結束時緩存數據即被釋放。我們也可以通過重寫模型管理器的方式實現更加復雜的緩存:
```
<pre class="calibre14">```
<?php
use Phalcon\Mvc\Model\Manager as ModelManager;
class CustomModelsManager extends ModelManager
{
/**
* Returns a reusable object from the cache
*
* @param string $modelName
* @param string $key
* @return object
*/
public function getReusableRecords($modelName, $key)
{
// If the model is Products use the APC cache
if ($modelName == 'Products') {
return apc_fetch($key);
}
// For the rest, use the memory cache
return parent::getReusableRecords($modelName, $key);
}
/**
* Stores a reusable record in the cache
*
* @param string $modelName
* @param string $key
* @param mixed $records
*/
public function setReusableRecords($modelName, $key, $records)
{
// If the model is Products use the APC cache
if ($modelName == 'Products') {
apc_store($key, $records);
return;
}
// For the rest, use the memory cache
parent::setReusableRecords($modelName, $key, $records);
}
}
```
```
別忘記注冊模型管理器到DI中:
```
<pre class="calibre14">```
<?php
$di->setShared('modelsManager', function () {
return new CustomModelsManager();
});
```
```
### 緩存相關記錄(Caching Related Records)
當使用find或findFirst查詢關聯數據時,ORM內部會自動的依據以下規則創建查詢條件于:
這意味著當我們取得關聯記錄時,我們需要解析如何如何取得數據的方法:
```
<pre class="calibre14">```
<?php
// Get some invoice
$invoice = Invoices::findFirst();
// Get the customer related to the invoice
$customer = $invoice->customer; // Invoices::findFirst('...');
// Same as above
$customer = $invoice->getCustomer(); // Invoices::findFirst('...');
```
```
因此,我們可以替換掉Invoices模型中的findFirst方法然后實現我們使用適合的方法
```
<pre class="calibre14">```
<?php
use Phalcon\Mvc\Model;
class Invoices extends Model
{
public static function findFirst($parameters = null)
{
// .. custom caching strategy
}
}
```
```
### 遞歸緩存相關記錄(Caching Related Records Recursively)
在這種場景下我們假定我們每次取主記錄時都會取模型的關聯記錄,如果我們此時保存這些記錄可能會為為我們的系統帶來一些性能上的提升:
```
<pre class="calibre14">```
<?php
use Phalcon\Mvc\Model;
class Invoices extends Model
{
protected static function _createKey($parameters)
{
// ... Create a cache key based on the parameters
}
protected static function _getCache($key)
{
// Returns data from a cache
}
protected static function _setCache($key)
{
// Stores data in the cache
}
public static function find($parameters = null)
{
// Create a unique key
$key = self::_createKey($parameters);
// Check if there are data in the cache
$results = self::_getCache($key);
// Valid data is an object
if (is_object($results)) {
return $results;
}
$results = array();
$invoices = parent::find($parameters);
foreach ($invoices as $invoice) {
// Query the related customer
$customer = $invoice->customer;
// Assign it to the record
$invoice->customer = $customer;
$results[] = $invoice;
}
// Store the invoices in the cache + their customers
self::_setCache($key, $results);
return $results;
}
public function initialize()
{
// Add relations and initialize other stuff
}
}
```
```
從已經緩存的訂單中取得用戶信息,可以減少系統的負載。注意我們也可以使用PHQL來實現這個,下面使用了PHQL來實現:
```
<pre class="calibre14">```
<?php
use Phalcon\Mvc\Model;
class Invoices extends Model
{
public function initialize()
{
// Add relations and initialize other stuff
}
protected static function _createKey($conditions, $params)
{
// ... Create a cache key based on the parameters
}
public function getInvoicesCustomers($conditions, $params = null)
{
$phql = "SELECT Invoices.*, Customers.*
FROM Invoices JOIN Customers WHERE " . $conditions;
$query = $this->getModelsManager()->executeQuery($phql);
$query->cache(
array(
"key" => self::_createKey($conditions, $params),
"lifetime" => 300
)
);
return $query->execute($params);
}
}
```
```
### 基于條件的緩存(Caching based on Conditions)
此例中,我依據當的條件實施緩存:
類型緩存1 - 10000mongo110000 - 20000mongo2> 20000mongo3最簡單的方式即是為模型類添加一個靜態的方法,此方法中我們指定要使用的緩存:
```
<pre class="calibre14">```
<?php
use Phalcon\Mvc\Model;
class Robots extends Model
{
public static function queryCache($initial, $final)
{
if ($initial >= 1 && $final < 10000) {
return self::find(
array(
'id >= ' . $initial . ' AND id <= '.$final,
'cache' => array(
'service' => 'mongo1'
)
)
);
}
if ($initial >= 10000 && $final <= 20000) {
return self::find(
array(
'id >= ' . $initial . ' AND id <= '.$final,
'cache' => array(
'service' => 'mongo2'
)
)
);
}
if ($initial > 20000) {
return self::find(
array(
'id >= ' . $initial,
'cache' => array(
'service' => 'mongo3'
)
)
);
}
}
}
```
```
這個方法是可以解決問題,不過如果我們需要添加其它的參數比如排序或條件等我們還要創建更復雜的方法。另外當我們使用find/findFirst來查詢關聯數據時此方法亦會失效:
```
<pre class="calibre14">```
<?php
$robots = Robots::find('id < 1000');
$robots = Robots::find('id > 100 AND type = "A"');
$robots = Robots::find('(id > 100 AND type = "A") AND id < 2000');
$robots = Robots::find(
array(
'(id > ?0 AND type = "A") AND id < ?1',
'bind' => array(100, 2000),
'order' => 'type'
)
);
```
```
為了實現這個我們需要攔截中間語言解析,然后書寫相關的代碼以定制緩存:首先我們需要創建自定義的創建器,然后我們可以使用它來創建守全自己定義的查詢:
```
<pre class="calibre14">```
<?php
use Phalcon\Mvc\Model\Query\Builder as QueryBuilder;
class CustomQueryBuilder extends QueryBuilder
{
public function getQuery()
{
$query = new CustomQuery($this->getPhql());
$query->setDI($this->getDI());
return $query;
}
}
```
```
這里我們返回的是CustomQuery而不是不直接的返回Phalcon\\Mvc\\Model\\Query, 類定義如下所示:
```
<pre class="calibre14">```
<?php
use Phalcon\Mvc\Model\Query as ModelQuery;
class CustomQuery extends ModelQuery
{
/**
* The execute method is overridden
*/
public function execute($params = null, $types = null)
{
// Parse the intermediate representation for the SELECT
$ir = $this->parse();
// Check if the query has conditions
if (isset($ir['where'])) {
// The fields in the conditions can have any order
// We need to recursively check the conditions tree
// to find the info we're looking for
$visitor = new CustomNodeVisitor();
// Recursively visits the nodes
$visitor->visit($ir['where']);
$initial = $visitor->getInitial();
$final = $visitor->getFinal();
// Select the cache according to the range
// ...
// Check if the cache has data
// ...
}
// Execute the query
$result = $this->_executeSelect($ir, $params, $types);
// Cache the result
// ...
return $result;
}
}
```
```
這里我們實現了一個幫助類用以遞歸的的檢查條件以查詢字段用以識我們知了需要使用緩存的范圍(即檢查條件以確認實施查詢緩存的范圍):
```
<pre class="calibre14">```
<?php
class CustomNodeVisitor
{
protected $_initial = 0;
protected $_final = 25000;
public function visit($node)
{
switch ($node['type']) {
case 'binary-op':
$left = $this->visit($node['left']);
$right = $this->visit($node['right']);
if (!$left || !$right) {
return false;
}
if ($left=='id') {
if ($node['op'] == '>') {
$this->_initial = $right;
}
if ($node['op'] == '=') {
$this->_initial = $right;
}
if ($node['op'] == '>=') {
$this->_initial = $right;
}
if ($node['op'] == '<') {
$this->_final = $right;
}
if ($node['op'] == '<=') {
$this->_final = $right;
}
}
break;
case 'qualified':
if ($node['name'] == 'id') {
return 'id';
}
break;
case 'literal':
return $node['value'];
default:
return false;
}
}
public function getInitial()
{
return $this->_initial;
}
public function getFinal()
{
return $this->_final;
}
}
```
```
最后,我們替換Robots模型中的查詢方法以使用我們創建的自定義類:
```
<pre class="calibre14">```
<?php
use Phalcon\Mvc\Model;
class Robots extends Model
{
public static function find($parameters = null)
{
if (!is_array($parameters)) {
$parameters = array($parameters);
}
$builder = new CustomQueryBuilder($parameters);
$builder->from(get_called_class());
if (isset($parameters['bind'])) {
return $builder->getQuery()->execute($parameters['bind']);
} else {
return $builder->getQuery()->execute();
}
}
}
```
```
### 緩存 PHQL 查詢計劃(Caching of PHQL planning)
像大多數現代的操作系統一樣PHQL內部會緩存執行計劃,如果同樣的語句多次執行,PHQL會使用之前生成的查詢計劃以提升系統的性能,對開發者來說只采用綁定參數的形式傳遞參數即可實現:
```
<pre class="calibre14">```
<?php
for ($i = 1; $i <= 10; $i++) {
$phql = "SELECT * FROM Store\Robots WHERE id = " . $i;
$robots = $this->modelsManager->executeQuery($phql);
// ...
}
```
```
上面的例子中,Phalcon產生了10個查詢計劃,這導致了應用的內存使用量增加。重寫以上代碼,我們使用綁定參數的這個優點可以減少系統和數據庫的過多操作:
```
<pre class="calibre14">```
<?php
$phql = "SELECT * FROM Store\Robots WHERE id = ?0";
for ($i = 1; $i <= 10; $i++) {
$robots = $this->modelsManager->executeQuery($phql, array($i));
// ...
}
```
```
得用PHQL查詢亦可以提供查詢性能:
```
<pre class="calibre14">```
<?php
$phql = "SELECT * FROM Store\Robots WHERE id = ?0";
$query = $this->modelsManager->createQuery($phql);
for ($i = 1; $i <= 10; $i++) {
$robots = $query->execute($phql, array($i));
// ...
}
```
```
\[`](#)預先準備的查詢語句`\_的查詢計劃亦可以被大多數的數據庫所緩存,這樣可以減少執行的時間,也可以使用我們的系統免受'SQL注入'\_的影響。
|
- [索引](# "總目錄")
- [下一頁](# "對象文檔映射 ODM (Object-Document Mapper)") |
- [上一頁](# "Phalcon 查詢語言(Phalcon Query Language (PHQL))") |
- API參考
- API列表
- Abstract class Phalcon\Acl
- Abstract class Phalcon\Acl\Adapter
- Class Phalcon\Acl\Adapter\Memory
- Interface Phalcon\Acl\AdapterInterface
- Class Phalcon\Acl\Exception
- Class Phalcon\Acl\Resource
- Interface Phalcon\Acl\ResourceInterface
- Class Phalcon\Acl\Role
- Interface Phalcon\Acl\RoleInterface
- Class Phalcon\Annotations\Annotation
- Abstract class Phalcon\Annotations\Adapter
- Interface Phalcon\Annotations\AdapterInterface
- Class Phalcon\Annotations\Collection
- Class Phalcon\Annotations\Exception
- Class Phalcon\Annotations\Reader
- Interface Phalcon\Annotations\ReaderInterface
- Class Phalcon\Annotations\Reflection
- Class Phalcon\Assets\Collection
- Class Phalcon\Assets\Exception
- Interface Phalcon\Assets\FilterInterface
- Class Phalcon\Assets\Filters\Cssmin
- Class Phalcon\Assets\Filters\Jsmin
- Class Phalcon\Assets\Filters\None
- Class Phalcon\Assets\Inline
- Class Phalcon\Assets\Inline\Css
- Class Phalcon\Assets\Inline\Js
- Class Phalcon\Assets\Manager
- Class Phalcon\Assets\Resource
- Class Phalcon\Assets\Resource\Css
- Class Phalcon\Assets\Resource\Js
- Abstract class Phalcon\Cache\Backend
- Class Phalcon\Cache\Backend\Apc
- Class Phalcon\Cache\Backend\File
- Class Phalcon\Cache\Backend\Libmemcached
- Class Phalcon\Cache\Backend\Memcache
- Class Phalcon\Cache\Backend\Memory
- Class Phalcon\Cache\Backend\Mongo
- Class Phalcon\Cache\Backend\Redis
- Class Phalcon\Cache\Backend\Xcache
- Interface Phalcon\Cache\BackendInterface
- Class Phalcon\Cache\Exception
- Class Phalcon\Cache\Frontend\Base64
- Class Phalcon\Cache\Frontend\Data
- Class Phalcon\Cache\Frontend\Igbinary
- Class Phalcon\Cache\Frontend\Json
- Class Phalcon\Cache\Frontend\None
- Class Phalcon\Cache\Frontend\Output
- Interface Phalcon\Cache\FrontendInterface
- Class Phalcon\Cache\Multiple
- Class Phalcon\Cli\Router\Route
- Class Phalcon\Config
- Class Phalcon\Config\Adapter\Ini
- Class Phalcon\Config\Adapter\Json
- Class Phalcon\Config\Adapter\Php
- Class Phalcon\Config\Adapter\Yaml
- Class Phalcon\Config\Exception
- Class Phalcon\Crypt
- Class Phalcon\Crypt\Exception
- Interface Phalcon\CryptInterface
- Abstract class Phalcon\Db
- Abstract class Phalcon\Db\Adapter
- Interface Phalcon\Db\AdapterInterface
- Class Phalcon\Db\Column
- Interface Phalcon\Db\ColumnInterface
- Abstract class Phalcon\Db\Dialect
- Interface Phalcon\Db\DialectInterface
- Class Phalcon\Db\Exception
- Class Phalcon\Db\Index
- Interface Phalcon\Db\IndexInterface
- Class Phalcon\Db\Profiler
- Class Phalcon\Db\RawValue
- Class Phalcon\Db\Reference
- Interface Phalcon\Db\ReferenceInterface
- Class Phalcon\Db\Result\Pdo
- Interface Phalcon\Db\ResultInterface
- Class Phalcon\Debug
- Class Phalcon\Debug\Dump
- Class Phalcon\Debug\Exception
- Interface Phalcon\DiInterface
- Abstract class Phalcon\Dispatcher
- Interface Phalcon\DispatcherInterface
- Class Phalcon\Escaper
- Class Phalcon\Escaper\Exception
- Interface Phalcon\EscaperInterface
- Class Phalcon\Events\Event
- Interface Phalcon\Events\EventsAwareInterface
- Class Phalcon\Events\Exception
- Class Phalcon\Events\Manager
- Interface Phalcon\Events\ManagerInterface
- Class Phalcon\Exception
- Class Phalcon\Filter
- Class Phalcon\Filter\Exception
- Interface Phalcon\Filter\UserFilterInterface
- Interface Phalcon\FilterInterface
- Abstract class Phalcon\Flash
- Class Phalcon\Flash\Direct
- Class Phalcon\Flash\Exception
- Class Phalcon\Flash\Session
- Interface Phalcon\FlashInterface
- Class Phalcon\Forms\Form
- Abstract class Phalcon\Forms\Element
- Class Phalcon\Forms\Exception
- Class Phalcon\Forms\Manager
- Class Phalcon\Http\Cookie
- Class Phalcon\Http\Cookie\Exception
- Class Phalcon\Http\Request
- Class Phalcon\Http\Request\Exception
- Class Phalcon\Http\Request\File
- Interface Phalcon\Http\Request\FileInterface
- Interface Phalcon\Http\RequestInterface
- Class Phalcon\Http\Response
- Class Phalcon\Http\Response\Cookies
- Interface Phalcon\Http\Response\CookiesInterface
- Class Phalcon\Http\Response\Exception
- Class Phalcon\Http\Response\Headers
- Interface Phalcon\Http\Response\HeadersInterface
- Interface Phalcon\Http\ResponseInterface
- Class Phalcon\Image
- Abstract class Phalcon\Image\Adapter
- Class Phalcon\Image\Adapter\Imagick
- Interface Phalcon\Image\AdapterInterface
- Class Phalcon\Image\Exception
- Class Phalcon\Kernel
- Class Phalcon\Loader
- Class Phalcon\Loader\Exception
- Abstract class Phalcon\Logger
- Abstract class Phalcon\Logger\Adapter
- Class Phalcon\Logger\Adapter\File
- Class Phalcon\Logger\Adapter\Firephp
- Class Phalcon\Logger\Adapter\Stream
- Class Phalcon\Logger\Adapter\Syslog
- Interface Phalcon\Logger\AdapterInterface
- Class Phalcon\Logger\Exception
- Abstract class Phalcon\Logger\Formatter
- Interface Phalcon\Logger\FormatterInterface
- Class Phalcon\Logger\Item
- Class Phalcon\Logger\Multiple
- Class Phalcon\Mvc\Application
- Class Phalcon\Mvc\Application\Exception
- Abstract class Phalcon\Mvc\Collection
- Abstract class Phalcon\Mvc\Collection\Behavior
- Class Phalcon\Mvc\Collection\Behavior\SoftDelete
- Class Phalcon\Mvc\Collection\Behavior\Timestampable
- Interface Phalcon\Mvc\Collection\BehaviorInterface
- Class Phalcon\Mvc\Collection\Document
- Class Phalcon\Mvc\Collection\Exception
- Class Phalcon\Mvc\Collection\Manager
- Interface Phalcon\Mvc\Collection\ManagerInterface
- Interface Phalcon\Mvc\CollectionInterface
- Abstract class Phalcon\Mvc\Controller
- Interface Phalcon\Mvc\ControllerInterface
- Class Phalcon\Mvc\Dispatcher
- Class Phalcon\Mvc\Dispatcher\Exception
- Interface Phalcon\Mvc\DispatcherInterface
- Interface Phalcon\Mvc\EntityInterface
- Class Phalcon\Mvc\Micro
- Class Phalcon\Mvc\Micro\Collection
- Interface Phalcon\Mvc\Micro\CollectionInterface
- Class Phalcon\Mvc\Micro\Exception
- Class Phalcon\Mvc\Micro\LazyLoader
- Interface Phalcon\Mvc\Micro\MiddlewareInterface
- Abstract class Phalcon\Mvc\Model
- Abstract class Phalcon\Mvc\Model\Behavior
- Class Phalcon\Mvc\Model\Criteria
- Interface Phalcon\Mvc\Model\CriteriaInterface
- Class Phalcon\Mvc\Model\Exception
- Class Phalcon\Mvc\Model\Manager
- Interface Phalcon\Mvc\Model\ManagerInterface
- Class Phalcon\Mvc\Model\Message
- Interface Phalcon\Mvc\Model\MessageInterface
- Abstract class Phalcon\Mvc\Model\MetaData
- Interface Phalcon\Mvc\Model\MetaDataInterface
- Class Phalcon\Mvc\Model\Query
- Interface Phalcon\Mvc\Model\QueryInterface
- Class Phalcon\Mvc\Model\Relation
- Interface Phalcon\Mvc\Model\RelationInterface
- Interface Phalcon\Mvc\Model\ResultInterface
- Abstract class Phalcon\Mvc\Model\Resultset
- Abstract class Phalcon\Mvc\Model\Validator
- Interface Phalcon\Mvc\Model\ResultsetInterface
- Class Phalcon\Mvc\Model\Row
- Class Phalcon\Mvc\Model\Transaction
- Interface Phalcon\Mvc\Model\TransactionInterface
- Class Phalcon\Mvc\Model\ValidationFailed
- Interface Phalcon\Mvc\ModelInterface
- Interface Phalcon\Mvc\ModuleDefinitionInterface
- Class Phalcon\Mvc\Router
- Class Phalcon\Mvc\Router\Annotations
- Class Phalcon\Mvc\Router\Exception
- Class Phalcon\Mvc\Router\Group
- Interface Phalcon\Mvc\Router\GroupInterface
- Class Phalcon\Mvc\Router\Route
- Interface Phalcon\Mvc\Router\RouteInterface
- Interface Phalcon\Mvc\RouterInterface
- Class Phalcon\Mvc\Url
- Class Phalcon\Mvc\Url\Exception
- Interface Phalcon\Mvc\UrlInterface
- Class Phalcon\Mvc\User\Component
- Class Phalcon\Mvc\User\Module
- Class Phalcon\Mvc\User\Plugin
- Class Phalcon\Mvc\View
- Abstract class Phalcon\Mvc\View\Engine
- Interface Phalcon\Mvc\View\EngineInterface
- Class Phalcon\Mvc\View\Exception
- Class Phalcon\Mvc\View\Simple
- Interface Phalcon\Mvc\ViewBaseInterface
- Interface Phalcon\Mvc\ViewInterface
- Abstract class Phalcon\Paginator\Adapter
- Class Phalcon\Paginator\Adapter\Model
- Class Phalcon\Paginator\Adapter\NativeArray
- Class Phalcon\Paginator\Adapter\QueryBuilder
- Interface Phalcon\Paginator\AdapterInterface
- Class Phalcon\Paginator\Exception
- Class Phalcon\Queue\Beanstalk
- Class Phalcon\Queue\Beanstalk\Job
- Final class Phalcon\Registry
- Class Phalcon\Security
- Class Phalcon\Security\Exception
- Abstract class Phalcon\Session
- Abstract class Phalcon\Session\Adapter
- Interface Phalcon\Session\AdapterInterface
- Class Phalcon\Session\Bag
- Interface Phalcon\Session\BagInterface
- Class Phalcon\Session\Exception
- Class Phalcon\Tag
- Class Phalcon\Tag\Exception
- Abstract class Phalcon\Tag\Select
- Abstract class Phalcon\Text
- Abstract class Phalcon\Translate
- Abstract class Phalcon\Translate\Adapter
- Class Phalcon\Translate\Adapter\Csv
- Class Phalcon\Translate\Adapter\Gettext
- Class Phalcon\Translate\Adapter\NativeArray
- Interface Phalcon\Translate\AdapterInterface
- Class Phalcon\Translate\Exception
- Class Phalcon\Validation
- Class Phalcon\Validation\Exception
- Class Phalcon\Validation\Message
- Class Phalcon\Validation\Message\Group
- Interface Phalcon\Validation\MessageInterface
- Abstract class Phalcon\Validation\Validator
- Class Phalcon\Validation\Validator\Alnum
- Class Phalcon\Validation\Validator\Alpha
- Class Phalcon\Validation\Validator\Between
- Class Phalcon\Validation\Validator\Confirmation
- Class Phalcon\Validation\Validator\Digit
- Class Phalcon\Validation\Validator\Email
- Class Phalcon\Validation\Validator\ExclusionIn
- Class Phalcon\Validation\Validator\File
- Class Phalcon\Validation\Validator\Identical
- Class Phalcon\Validation\Validator\InclusionIn
- Class Phalcon\Validation\Validator\Numericality
- Class Phalcon\Validation\Validator\PresenceOf
- Class Phalcon\Validation\Validator\Regex
- Class Phalcon\Validation\Validator\StringLength
- Class Phalcon\Validation\Validator\Uniqueness
- Class Phalcon\Validation\Validator\Url
- Interface Phalcon\Validation\ValidatorInterface
- Class Phalcon\Version
- 參考手冊
- 安裝(Installation)
- 教程 1:讓我們通過例子來學習(Tutorial 1: Let’s learn by example)
- 教程 2:Introducing INVO(Tutorial 2: Introducing INVO)
- 教程 3: Securing INVO
- 教程 4: Using CRUDs
- 教程 5: Customizing INVO
- 教程 6: Vkuró
- 教程 7:創建簡單的 REST API(Tutorial 7: Creating a Simple REST API)
- 示例列表(List of examples)
- 依賴注入與服務定位器(Dependency Injection/Service Location)
- MVC 架構(The MVC Architecture)
- 使用控制器(Using Controllers)
- 使用模型(Working with Models)
- 模型元數據(Models Meta-Data)
- 事務管理(Model Transactions)
- Phalcon 查詢語言(Phalcon Query Language (PHQL))
- 緩存對象關系映射(Caching in the ORM)
- 對象文檔映射 ODM (Object-Document Mapper)
- 使用視圖(Using Views)
- 視圖助手(View Helpers)
- 資源文件管理(Assets Management)
- Volt 模版引擎(Volt: Template Engine)
- MVC 應用(MVC Applications)
- 路由(Routing)
- 調度控制器(Dispatching Controllers)
- 微應用(Micro Applications)
- 使用命名空間(Working with Namespaces)
- 事件管理器(Events Manager)
- Request Environment
- 返回響應(Returning Responses)
- Cookie 管理(Cookies Management)
- 生成 URL 和 路徑(Generating URLs and Paths)
- 閃存消息(Flashing Messages)
- 使用 Session 存儲數據(Storing data in Session)
- 過濾與清理(Filtering and Sanitizing)
- 上下文編碼(Contextual Escaping)
- 驗證(Validation)
- 表單(Forms)
- 讀取配置(Reading Configurations)
- 分頁(Pagination)
- 使用緩存提高性能(Improving Performance with Cache)
- 安全(Security)
- Encryption/Decryption
- 訪問控制列表 ACL(Access Control Lists ACL)
- 多語言支持(Multi-lingual Support)
- Universal Class Loader
- 日志記錄(Logging)
- 注釋解析器(Annotations Parser)
- 命令行應用(Command Line Applications)
- 隊列(Queueing)
- 數據庫抽象層(Database Abstraction Layer)
- 國際化(Internationalization)
- 數據庫遷移(Database Migrations)
- 調試應用程序(Debugging Applications)
- Phalcon 開發工具(Phalcon Developer Tools)
- 提高性能:下一步該做什么?(Increasing Performance: What’s next?)
- 單元測試(Unit testing)
- 授權(License)