# Phalcon 分享第二季
- [Phalcon 分享第二季](page-1.xhtml#toc_0)
- [一、前言](page.xhtml#toc_1)
- [二、模型](page1.xhtml#toc_2)
- [2.1 映射其他表](page1.xhtml#toc_3)
- [2.2 Setters/Getters](page1.xhtml#toc_4)
- [2.2.1 不使用](page1.xhtml#toc_5)
- [2.2.2 使用](page1.xhtml#toc_6)
- [2.2.3 比較](page1.xhtml#toc_7)
- [2.2.4 注意](page1.xhtml#toc_8)
- [2.3 理解記錄對象](page1.xhtml#toc_9)
- [2.3.1 model中查詢記錄](page1.xhtml#toc_10)
- [1. 查詢值](page1.xhtml#toc_11)
- [2. 修改值](page1.xhtml#toc_12)
- [2.3.2 查找記錄](page1.xhtml#toc_13)
- [1. find()基本查詢](page1.xhtml#toc_14)
- [2. 查詢條件](page1.xhtml#toc_15)
- [3. 綁定查詢特性](page1.xhtml#toc_16)
- [4. 綁定查詢方式](page1.xhtml#toc_17)
- [2.3.4 模型結果集](page1.xhtml#toc_18)
- [1. 假設結果集](page1.xhtml#toc_19)
- [2. 循環結果集](page1.xhtml#toc_20)
- [3. 結果集總數](page1.xhtml#toc_21)
- [4. 結果集指針操作](page1.xhtml#toc_22)
- [5. 結果集總結](page1.xhtml#toc_23)
- [2.3.5 過濾結果集](page1.xhtml#toc_24)
- [2.3.6 獲取記錄的初始化以及準備](page1.xhtml#toc_25)
- [2.3.7 生成運算](page1.xhtml#toc_26)
- [1. count](page1.xhtml#toc_27)
- [2. Sum](page1.xhtml#toc_28)
- [3. Average](page1.xhtml#toc_29)
- [4. Max/Min](page1.xhtml#toc_30)
- [2.3.8 創建與更新記錄](page1.xhtml#toc_31)
- [1. 單獨屬性賦值保存](page1.xhtml#toc_32)
- [2. 數組賦值保存](page1.xhtml#toc_33)
- [3. form傳值保存](page1.xhtml#toc_34)
- [2.3.9 創建與更新結果判斷](page1.xhtml#toc_35)
- [2.3.10 刪除記錄](page1.xhtml#toc_36)
- [1. 刪除一條記錄](page1.xhtml#toc_37)
- [2. 刪除多條記錄](page1.xhtml#toc_38)
- [3. 刪除時可執行方法](page1.xhtml#toc_39)
- [三、模型關系](page2.xhtml#toc_40)
- [3.1 模型關系](page2.xhtml#toc_41)
- [3.2 單向關系](page2.xhtml#toc_42)
- [3.3 雙向關系](page2.xhtml#toc_43)
- [3.4 定義關系](page2.xhtml#toc_44)
- [3.5 數據表結構(舉例)](page2.xhtml#toc_45)
- [3.6 關系模型實現](page2.xhtml#toc_46)
- [1. Robots 模型](page2.xhtml#toc_47)
- [2. Parts 模型](page2.xhtml#toc_48)
- [3. RobotsParts 模型](page2.xhtml#toc_49)
- [4. 如上模型字段說明](page2.xhtml#toc_50)
- [5. 多對對關系](page2.xhtml#toc_51)
- [3.7 使用關系](page2.xhtml#toc_52)
- [3.7.1 使用相同屬性名稱](page2.xhtml#toc_53)
- [3.7.2 getter](page2.xhtml#toc_54)
- [3.7.3 是否使用魔術方法比較](page2.xhtml#toc_55)
- [1. 魔術方法(get前綴)](page2.xhtml#toc_56)
- [2. 手動方法](page2.xhtml#toc_57)
- [3. 總結](page2.xhtml#toc_58)
- [4. count前綴](page2.xhtml#toc_59)
- [3.8 定義關系](page2.xhtml#toc_60)
- [3.8.1 RobotsSimilar模型](page2.xhtml#toc_61)
- [3.8.2 aliases解決問題](page2.xhtml#toc_62)
- [3.9 Getters vs. Explicit](page2.xhtml#toc_63)
- [3.10 虛擬外鍵](page2.xhtml#toc_64)
- - [1. 使用虛擬外鍵](page2.xhtml#toc_65)
- [2. 驗證外鍵](page2.xhtml#toc_66)
- [3. 設置空值](page2.xhtml#toc_67)
- [3.11 級聯與限制動作](page2.xhtml#toc_68)
- [3.12 存儲關系記錄](page2.xhtml#toc_69)
- [2.13 更新關聯表記錄](page2.xhtml#toc_70)
- [2.14 刪除關聯表記錄](page2.xhtml#toc_71)
- [四、模型事件](page3.xhtml#toc_72)
- [4.1 事件與事件管理器](page3.xhtml#toc_73)
- [4.2 模型中自定義事件](page3.xhtml#toc_74)
- [4.2.1 直接使用](page3.xhtml#toc_75)
- [4.2.2 定義值](page3.xhtml#toc_76)
- [4.3 使用自定義事件管理器](page3.xhtml#toc_77)
- [4.4 記錄底層 SQL 語句](page3.xhtml#toc_78)
- [4.5 分析 SQL 語句](page3.xhtml#toc_79)
- [五、模型行為](page4.xhtml#toc_80)
- [5.1 內置行為](page4.xhtml#toc_81)
- [5.2 生成時間戳](page4.xhtml#toc_82)
- [5.3 軟刪除](page4.xhtml#toc_83)
- [5.4 創建行為](page4.xhtml#toc_84)
- [5.5 使用 Traits 實現行為](page4.xhtml#toc_85)
- [5.5.1 Traits參考](page4.xhtml#toc_86)
- [六、模型元數據](page5.xhtml#toc_87)
- [6.1 緩存元數據](page5.xhtml#toc_88)
- [6.2 元數據策略](page5.xhtml#toc_89)
- [6.3 數據庫內部策略](page5.xhtml#toc_90)
- [6.4 注釋策略](page5.xhtml#toc_91)
- [6.5 自定義元數據(未翻譯)](page5.xhtml#toc_92)
- [七、事務管理](page6.xhtml#toc_93)
- [7.1 自定義事務](page6.xhtml#toc_94)
- [7.2 隱含的事務](page6.xhtml#toc_95)
- [7.3 單獨的事務](page6.xhtml#toc_96)
- [7.3.1 事務管理器](page6.xhtml#toc_97)
- [7.3.2 刪除多條記錄](page6.xhtml#toc_98)
- [7.3.3 全局事務管理器](page6.xhtml#toc_99)
- [1. 注冊服務](page6.xhtml#toc_100)
- [2. 訪問](page6.xhtml#toc_101)
- [八、驗證模型](page7.xhtml#toc_102)
- [8.1 InclusionIn](page7.xhtml#toc_103)
- [8.2 可重用](page7.xhtml#toc_104)
- [8.3 驗證信息](page7.xhtml#toc_105)
- [8.4 驗證消息類型](page7.xhtml#toc_106)
- [8.5 驗證失敗事件](page7.xhtml#toc_107)
- [九、使用Model(進階)](page8.xhtml#toc_108)
- [9.1 stackoverflow實例 (HYDRATE)](page8.xhtml#toc_109)
- [9.1.1 HYDRATE\_ARRAY](page8.xhtml#toc_110)
- [9.1.2 HYDRATE\_RECORD](page8.xhtml#toc_111)
- [9.1.3 HYDRATE\_SINGULAR\_SCALAR](page8.xhtml#toc_112)
- [9.2 Hydration Modes](page8.xhtml#toc_113)
- [9.3 自動生成標識列](page8.xhtml#toc_114)
- [9.4 忽略指定列的數據](page8.xhtml#toc_115)
- [9.5 動態更新](page8.xhtml#toc_116)
- [9.6 獨立的列映射](page8.xhtml#toc_117)
- [9.7 記錄快照](page8.xhtml#toc_118)
- [9.8 設置模式](page8.xhtml#toc_119)
- [9.9 設置多個數據庫](page8.xhtml#toc_120)
- [9.9.1 注冊DB服務](page8.xhtml#toc_121)
- [9.9.2 定義數據庫鏈接](page8.xhtml#toc_122)
- [9.9.3 設置讀寫](page8.xhtml#toc_123)
- [9.9.4 shard選擇器](page8.xhtml#toc_124)
- [9.10 注入服務到模型](page8.xhtml#toc_125)
- [9.11 禁用或啟用特性](page8.xhtml#toc_126)
- [9.12 獨立的組件](page8.xhtml#toc_127)
- [十、PHQL](page9.xhtml#toc_128)
- [10.1 范例](page9.xhtml#toc_129)
- [10.1.1 Cars model](page9.xhtml#toc_130)
- [10.1.2 Brands model](page9.xhtml#toc_131)
- [10.2 創建 PHQL 查詢](page9.xhtml#toc_132)
- [10.2.1 實例化Query方式](page9.xhtml#toc_133)
- [10.2.2 models manager方式](page9.xhtml#toc_134)
- [10.2.3 更簡單的執行方式:](page9.xhtml#toc_135)
- [10.3 選取記錄](page9.xhtml#toc_136)
- [10.4 結果類型](page9.xhtml#toc_137)
- [10.4.1 原生Sql語句](page9.xhtml#toc_138)
- [10.4.2 PHQL語句](page9.xhtml#toc_139)
- [10.4.3 查詢部分值](page9.xhtml#toc_140)
- [10.5 Joins查詢](page9.xhtml#toc_141)
- [10.5.1 使用Join查詢](page9.xhtml#toc_142)
- [10.5.2 設置Join類型](page9.xhtml#toc_143)
- [10.5.3 手動設置Join條件](page9.xhtml#toc_144)
- [1. JOIN ON方式](page9.xhtml#toc_145)
- [2. FROM方式](page9.xhtml#toc_146)
- [3. FROM別名方式](page9.xhtml#toc_147)
- [4. 隱式添加](page9.xhtml#toc_148)
- [10.6 聚合](page9.xhtml#toc_149)
- [10.6.1 SUM](page9.xhtml#toc_150)
- [10.6.2 COUNT](page9.xhtml#toc_151)
- [10.6.3 MAX、MIN](page9.xhtml#toc_152)
- [10.6.4 Count distinct](page9.xhtml#toc_153)
- [10.7 條件](page9.xhtml#toc_154)
- [10.8 插入數據](page9.xhtml#toc_155)
- [10.9 更新數據](page9.xhtml#toc_156)
- [10.10 刪除數據](page9.xhtml#toc_157)
- [10.11 查詢構建器](page9.xhtml#toc_158)
- [10.12 綁定參數](page9.xhtml#toc_159)
- [10.13 禁止使用字面值](page9.xhtml#toc_160)
- [10.14 轉義保留字](page9.xhtml#toc_161)
- [10.15 PHQL 生命周期](page9.xhtml#toc_162)
- [10.16 使用原生 SQL](page9.xhtml#toc_163)
- [10.17 注意事項](page9.xhtml#toc_164)
- [十一、緩存對象關系映射 (ORM)](page10.xhtml#toc_165)
- [11.1 緩存結果集](page10.xhtml#toc_166)
- [11.1.1 注冊服務](page10.xhtml#toc_167)
- [11.1.2 使用緩存](page10.xhtml#toc_168)
- [11.1.3 緩存查詢關聯表](page10.xhtml#toc_169)
- [11.2 強制緩存](page10.xhtml#toc_170)
- [11.2.1 cache作參數](page10.xhtml#toc_171)
- [11.2.2 緩存所有查詢](page10.xhtml#toc_172)
- [11.2.3 緩存基類](page10.xhtml#toc_173)
- [11.3 緩存PHQL查詢](page10.xhtml#toc_174)
- [11.4 可重用的相關記錄](page10.xhtml#toc_175)
- [11.5 緩存相關記錄](page10.xhtml#toc_176)
- [11.6 遞歸緩存相關記錄](page10.xhtml#toc_177)
- [11.7 緩存PHQL查詢計劃](page10.xhtml#toc_178)
- [十二、 路由](page11.xhtml#toc_179)
- [12.1 定義路由](page11.xhtml#toc_180)
- [12.1.1 單獨定義](page11.xhtml#toc_181)
- [12.1.2 批量定義](page11.xhtml#toc_182)
- [12.1.3 占位符](page11.xhtml#toc_183)
- [12.2 參數名稱](page11.xhtml#toc_184)
- [12.3 短語法](page11.xhtml#toc_185)
- [12.4 混合使用數組和短語法](page11.xhtml#toc_186)
- [12.5 路由到模塊](page11.xhtml#toc_187)
- [12.6 限制HTTP請求傳入方式](page11.xhtml#toc_188)
- [12.7 使用轉換](page11.xhtml#toc_189)
- [12.8 路由分組](page11.xhtml#toc_190)
- [12.9 匹配路由](page11.xhtml#toc_191)
- [12.10 路由命名](page11.xhtml#toc_192)
- [12.11 范例](page11.xhtml#toc_193)
- [12.12 默認行為](page11.xhtml#toc_194)
- [12.13 設置默認路由](page11.xhtml#toc_195)
- [12.14 沒有找到路徑](page11.xhtml#toc_196)
- [12.15 設置默認路徑](page11.xhtml#toc_197)
- [12.16 處理結尾額外的斜桿](page11.xhtml#toc_198)
- [12.17 匹配回調函數](page11.xhtml#toc_199)
- [12.18 測試路由](page11.xhtml#toc_200)
- [12.19 注解路由](page11.xhtml#toc_201)
- [十三、 調度控制器](page12.xhtml#toc_202)
- [13.1 循環調度](page12.xhtml#toc_203)
- [13.2 循環調度事件](page12.xhtml#toc_204)
- [13.3 轉發到其他動作](page12.xhtml#toc_205)
- [13.3.1 跳轉](page12.xhtml#toc_206)
- [13.3.2 傳遞參數](page12.xhtml#toc_207)
- [13.3.3 可用參數](page12.xhtml#toc_208)
- [13.4 準備參數](page12.xhtml#toc_209)
- [13.5 獲取參數](page12.xhtml#toc_210)
- [13.6 轉換動作名](page12.xhtml#toc_211)
- [13.7 刪除遺留的擴展名](page12.xhtml#toc_212)
- [13.8 注入模型實例](page12.xhtml#toc_213)
- [13.9 處理 Not-Found 錯誤](page12.xhtml#toc_214)
- [十四、 使用命名空間](page13.xhtml#toc_215)
- [14.1 設置框架](page13.xhtml#toc_216)
- [14.1.1 設置常規命名空間](page13.xhtml#toc_217)
- [14.1.2 設置默認命名空間](page13.xhtml#toc_218)
- [14.2 控制器加入命名空間](page13.xhtml#toc_219)
- [14.3 模型加入命名空間](page13.xhtml#toc_220)
- [14.3.1 常規引入](page13.xhtml#toc_221)
- [14.3.2 對應關系引入](page13.xhtml#toc_222)
- [14.3.3 PHQL中注意](page13.xhtml#toc_223)
- [十五、事件管理器](page14.xhtml#toc_224)
- [15.1 命名約定](page14.xhtml#toc_225)
- [15.2 使用示例](page14.xhtml#toc_226)
- [15.3 創建組件觸發事件](page14.xhtml#toc_227)
- [15.4 使用DI服務](page14.xhtml#toc_228)
- [15.5 事件傳播與取消](page14.xhtml#toc_229)
- [15.6 偵聽器優先級](page14.xhtml#toc_230)
- [15.7 收集響應](page14.xhtml#toc_231)
- [十六、 Request Environment](page15.xhtml#toc_232)
- [16.1 獲取值](page15.xhtml#toc_233)
- [16.2 控制器中訪問請求](page15.xhtml#toc_234)
- [16.3 使用頭信息](page15.xhtml#toc_235)
- [十七、返回響應](page16.xhtml#toc_236)
- [17.1 使用頭部信息(Working with Headers)](page16.xhtml#toc_237)
- [17.2 重定向](page16.xhtml#toc_238)
- [17.3 HTTP 緩存](page16.xhtml#toc_239)
- [設置過期時間](page16.xhtml#toc_240)
- [17.4 Cache-Control](page16.xhtml#toc_241)
- [17.5 E-Tag](page16.xhtml#toc_242)
- [十八、Cookie 管理](page17.xhtml#toc_243)
- [18.1 基本使用](page17.xhtml#toc_244)
- [18.2 Cookie 的加密和解密](page17.xhtml#toc_245)
- [十九、分頁](page18.xhtml#toc_246)
- [19.1 數據適配器](page18.xhtml#toc_247)
- [19.2 示例](page18.xhtml#toc_248)
- [19.2.1 model代碼](page18.xhtml#toc_249)
- [19.2.2 view代碼](page18.xhtml#toc_250)
- [19.2.3 導航代碼](page18.xhtml#toc_251)
- [19.3 適配器使用](page18.xhtml#toc_252)
- [19.4 頁面屬性](page18.xhtml#toc_253)
- [二十、閃存消息](page19.xhtml#toc_254)
- [20.1 適配器](page19.xhtml#toc_255)
- [20.2 使用](page19.xhtml#toc_256)
- [20.2.1 注冊服務](page19.xhtml#toc_257)
- [20.2.2 控制器、視圖調用](page19.xhtml#toc_258)
- [20.3 消息支持](page19.xhtml#toc_259)
- [20.3.1 內置消息](page19.xhtml#toc_260)
- [20.3.2 自定義消息](page19.xhtml#toc_261)
- [20.4 輸出信息](page19.xhtml#toc_262)
- [20.5 傳遞樣式](page19.xhtml#toc_263)
- [20.6 絕對刷送與會話](page19.xhtml#toc_264)
- [20.6.1 轉發](page19.xhtml#toc_265)
- [20.6.2 HTTP重定向](page19.xhtml#toc_266)
- [二十一、使用 Session](page20.xhtml#toc_267)
- [21.1 啟動會話](page20.xhtml#toc_268)
- [21.2 存儲與讀取](page20.xhtml#toc_269)
- [21.3 刪除和銷毀](page20.xhtml#toc_270)
- [二十二、過濾與清理](page21.xhtml#toc_271)
- [22.1 內置過濾器類型](page21.xhtml#toc_272)
- [22.2 清理數據](page21.xhtml#toc_273)
- [22.3 在控制器中使用清理](page21.xhtml#toc_274)
- [22.4 過濾action參數](page21.xhtml#toc_275)
- [22.5 過濾數據](page21.xhtml#toc_276)
- [22.6 組合過濾](page21.xhtml#toc_277)
- [22.7 創建過濾器](page21.xhtml#toc_278)
- [二十三、讀取配置](page22.xhtml#toc_279)
- [23.1 原生數組](page22.xhtml#toc_280)
- [23.2 文件適配器](page22.xhtml#toc_281)
- [23.3 讀取INI文件](page22.xhtml#toc_282)
- [23.4 合并配置](page22.xhtml#toc_283)
- [23.5 注冊DI](page22.xhtml#toc_284)
- [二十四、訪問控制列表 ACL](page23.xhtml#toc_285)
- [24.1 創建 ACL](page23.xhtml#toc_286)
- [24.2 添加角色](page23.xhtml#toc_287)
- [24.3 添加資源](page23.xhtml#toc_288)
- [24.4 定義訪問控制](page23.xhtml#toc_289)
- [24.5 查詢 ACL](page23.xhtml#toc_290)
- [24.6 基于功能的訪問](page23.xhtml#toc_291)
- [24.7 Objects as role name and resource name](page23.xhtml#toc_292)
- [24.7.1 UserRole class](page23.xhtml#toc_293)
- [24.7.2 ModelResource class](page23.xhtml#toc_294)
- [24.7.3 isAllowed() 方法](page23.xhtml#toc_295)
- [24.8 角色繼承](page23.xhtml#toc_296)
- [24.9 序列化 ACL 列表](page23.xhtml#toc_297)
- [24.10 ACL 事件](page23.xhtml#toc_298)
- [二十五、類加載器](page24.xhtml#toc_299)
- [25.1 安全層](page24.xhtml#toc_300)
- [25.2 注冊命名空間](page24.xhtml#toc_301)
- [25.3 注冊文件夾](page24.xhtml#toc_302)
- [25.4 注冊類名](page24.xhtml#toc_303)
- [25.5 注冊文件](page24.xhtml#toc_304)
- [25.6 額外的擴展名](page24.xhtml#toc_305)
- [25.7 修改當前策略](page24.xhtml#toc_306)
- [25.8 自動加載事件](page24.xhtml#toc_307)
- [25.9 注意事項](page24.xhtml#toc_308)
- [二十六、日志記錄](page25.xhtml#toc_309)
- [26.1 適配器](page25.xhtml#toc_310)
- [26.2 創建日志](page25.xhtml#toc_311)
- [26.3 事務](page25.xhtml#toc_312)
- [26.4 使用多個處理程序進行日志記錄](page25.xhtml#toc_313)
- [26.5 信息格式](page25.xhtml#toc_314)
- [26.6 行格式化處理](page25.xhtml#toc_315)
- [26.7 文件日志記錄器](page25.xhtml#toc_316)
- [26.8 Syslog 日志記錄器](page25.xhtml#toc_317)