# 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)