SugarCRM之ControllerFactory类分析
来源:互联网 发布:网络诈骗的案例 编辑:程序博客网 时间:2024/05/23 01:56
- 1、定义了模块(module)类的命名规范,如下:
- 1、把{模块名}首字母转换为大写
- 2、{类名}={模块名}+Controller
- 3、{自定义类名}=Custom+{模块名}+Controller
- 2、创建控制器实例的流程
- 1、如果存在'custom/modules/{模块名}/controller.php'控制器则使用{自定义类名}创建一个控制器实例,否则使用{类名}创建一个控制器实例。否则执行下面的2条件:
- 2、如果存在'modules/{模块名}/controller.php'控制器则使用{自定义类名}创建一个控制器实例,否则使用{类名}创建一个控制器实例。否则执行下面的3条件:
- 3、如果存在CustomSugarController类则创建CustomSugarController控制器。否则执行下面的4条件:
- 4、如果存在SugarController类则创建SugarController控制器
- 3、$controller->setup($module)设置控制器实例的属性值以及action映射,这些属性的值都是从请求URL得到,如下:
- 1、设置 module 属性值
- 2、设置 action 属性值
- 3、设置 record 属性值
- 4、设置 view 属性值
- 5、设置 return_module 属性值
- 6、设置 return_action 属性值
- 7、设置 return_id 属性值
- 8、加载 action_view_map.php 文件,此值从以下目录加载,越往下的目录其优先级越高,即会覆盖之前的 action_view_map 属性值
- 1、include/MV/Controller/action_view_map.php
- 2、modules/{module}/action_view_map.php
- 3、custom/modules/{module}/action_view_map.php
- 4、custom/include/MV/Controller/action_view_map.php
- 5、custom/application/Ex/ActionViewMap/action_view_map.ext.php
- 6、custom/modules/{module}/Ex/ActionViewMap/action_view_map.ext.php
- 7、从缓存加载,缓存名表示为:CONTROLLER_action_view_map_{module}
- 注1:
此文件只有一个数组变量$action_view_map,格式为'{action名}' => '{view名}',比如:
$action_view_map['detailview']= 'detail';其涵义为:detailview动作对应的视图文件为view.detail.php - 注2:
加载(require)完后会保存到由CONTROLLER_action_view_map_{module}标识的缓存,方便下次直接从缓存读取以提高效率。 - 9、加载 action_file_map.php 文件,此值从以下目录加载,越往下的目录其优先级越高,即会覆盖之前的 action_file_map 属性值
- 1、include/MV/Controller/action_file_map.php
- 2、modules/{module}/action_file_map.php
- 3、custom/modules/{module}/action_file_map.php
- 4、custom/include/MV/Controller/action_file_map.php
- 5、custom/application/Ex/ActionFileMap/action_file_map.ext.php
- 6、custom/modules/{module}/Ex/ActionFileMap/action_file_map.ext.php
- 7、从缓存加载,缓存名表示为:CONTROLLER_action_file_map_{module}
- 注1:
此文件只有一个数组变量$action_file_map,格式为:'{action名}' => '{文件名}',比如:
$action_file_map['save2']= 'include/generic/Save2.php';其涵义为:save2动作映射到include/generic/Save2.php文件 - 注2:
加载(require)完后会保存到由CONTROLLER_action_file_map_{module}标识的缓存,方便下次直接从缓存读取以提高效率。 - 10、加载 action_remap.php 文件,此值从以下目录加载,越往下的目录其优先级越高,即会覆盖之前的 action_remap 属性值
- 1、include/MV/Controller/action_remap.php
- 2、modules/{module}/action_remap.php
- 3、custom/modules/{module}/action_remap.php
- 4、custom/include/MV/Controller/action_remap.php
- 5、custom/application/Ex/ActionRemap/action_remap.ext.php
- 6、custom/modules/{module}/Ex/ActionRemap/action_remap.ext.php
- 7、从缓存加载,缓存名表示为:CONTROLLER_action_remap_{module}
- 注1:
此文件只有一个数组变量$action_remap',格式为:'{action名}' => '{view名}',比如:
$action_remap['detailview']= 'detail';其涵义为:detailview动作对应的视图文件为view.detail.php - 注2:
加载(require)完后会保存到由CONTROLLER_action_remap_{module}标识的缓存,方便下次直接从缓存读取以提高效率。 - 11、设置 var 属性值,var属性值实际是由上面第8、9、10提供的。
(探讨请加微信:JiangHuKeyKe)
<?phprequire_once('include/MVC/Controller/SugarController.php');/** * MVC控制器工厂 * @api */class ControllerFactory{ /** * 获取正确控制器的实例。 * * @return 返回一个控制器实例 */ function getController($module){ $class = ucfirst($module).'Controller'; $customClass = 'Custom' . $class; if(file_exists('custom/modules/'.$module.'/controller.php')){ $customClass = 'Custom' . $class; require_once('custom/modules/'.$module.'/controller.php'); if(class_exists($customClass)){ $controller = new $customClass(); }else if(class_exists($class)){ $controller = new $class(); } }elseif(file_exists('modules/'.$module.'/controller.php')){ require_once('modules/'.$module.'/controller.php'); if(class_exists($customClass)){ $controller = new $customClass(); }else if(class_exists($class)){ $controller = new $class(); } }else{ if(file_exists('custom/include/MVC/Controller/SugarController.php')){ require_once('custom/include/MVC/Controller/SugarController.php'); } if(class_exists('CustomSugarController')){ $controller = new CustomSugarController(); }else{ $controller = new SugarController(); } } //setup the controller $controller->setup($module); return $controller; } }?>
阅读全文
0 0
- SugarCRM之ControllerFactory类分析
- SugarCRM源码分析之ControllerFactory
- SugarCRM之SugarAutoLoader类分析
- SugarCRM源码分析之loadFileMap
- SugarCRM源码分析之loadComposer
- SugarCRM源码分析之数据库连接
- SugarCRM源码分析之日志
- SugarCRM源码分析之钩子
- SugarCRM源码分析之缓存
- SugarCRM源码分析之ViewFactory
- SugarCRM源码分析之BeanFactory
- SugarCRM之entryPoint文件分析
- SugarCRM源码分析之加载配置
- SugarCRM源码分析之SugarAutoLoader::init
- SugarCRM源码分析之国际化语言
- SugarCRM源码分析之日期时间
- SugarCRM源码分析之本地化货币
- sugarcrm
- RxSwift
- 从头到尾彻底理解傅里叶变换算法
- Vmware克隆Linux虚拟机后网卡修改办法
- PEP8:python编程规范
- android带反弹效果ScrollView
- SugarCRM之ControllerFactory类分析
- 文章标题
- CSS样式 ul li 标签的坑
- 统计支付宝交易sql
- ListView 复用学习
- 通配符
- 代理模式(Proxy)
- 基于Qualcomm平台的Camera OS
- mysql添加列、删除列,创建主键、备份等常用操作总结