关闭

mage_core_model_resource---------系统资源模型分析!!!!

412人阅读 评论(0) 收藏 举报
mage_core_model_resource_abstract.php 1.1 //* Instances of classes for connection types protected $_connectionTypes = array(); 1.2 //Instances of actual connections protected $_connections = array(); 1.3 // Creates a connection to resource whenever needed @return mixed public function getConnection($name) 1.4 //被getConnection调用 protected function _getDefaultConnection($requiredConnectionName) 1.5 //Get connection type instance @return Mage_Core_Model_Resource_Type_Abstract public function getConnectionTypeInstance($type) 1.6 //Get resource entity @return Varien_Simplexml_Config public function getEntity($model, $entity) 1.7 //Get resource table name @return string public function getTableName($modelEntity) 1.8 public function createConnection($name, $type, $config) 基本上是表信息的取得,在varien_db_adapter_pro_mysql的基础上取到connection。 **************************************************************************** 由此类引申出来如可得到配置文件里面的table值--> $resourceModel = (string) Mage::getConfig()->getNode()->global->models-> {$model}->resourceModel; $entityConfig = $this->getEntity($resourceModel, $entity); if ($entityConfig) { $tableName = (string)$entityConfig->table; 附上一段配置文件代码: Mage_Catalog_Model catalog_resource_eav_mysql4 Mage_Catalog_Model_Resource_Eav_Mysql4 catalog_product_entity
2 abstract class Mage_Core_Model_Resource_Abstract 2.1 // * Start resource transaction @return Mage_Core_Model_Resource_Abstract public function beginTransaction() { $this->_getWriteAdapter()->beginTransaction(); return $this; } 2.2 //Subscribe some callback to transaction commit @return Mage_Core_Model_Resource_Abstract public function addCommitCallback($callback) 2.3 //Commit resource transaction @return Mage_Core_Model_Resource_Abstract public function commit() 2.4 //Roll back resource transaction @return Mage_Core_Model_Resource_Abstract public function rollBack() 2.5 // Format date to internal format public function formatDate($date, $includeTime=true) 2.6 public function mktime($str) 2.7 //Serialize specified field in an object protected function _serializeField(Varien_Object $object, $field, $defaultValue = null, $unsetEmpty = false) 2.8 //Unserialize Varien_Object field in an object protected function _unserializeField(Varien_Object $object, $field, $defaultValue = null) 数据库 2.1 事务方面的处理, 2.2 序列化字段 2.3 时间等格式处理。 比较明显的就是事务的处理!! 3 由 abstract class Mage_Core_Model_Resource_Abstract 可以延伸至 abstract class Mage_Core_Model_Resource_Type_Abstract protected $_entityClass = 'Mage_Core_Model_Resource_Entity_Abstract'; public function getEntityClass() { return $this->_entityClass; } public function setName($name) { $this->_name = $name; } public function getName() { return $this->_name; } 4 延伸至 abstract class Mage_Core_Model_Resource_Entity_Abstract { protected $_name = null; protected $_config = array(); public function __construct($config) { $this->_config = $config; } public function getConfig($key='') { if (''===$key) { return $this->_config; } elseif (isset($this->_config->$key)) { return $this->_config->$key; } else { return false; } } } 5 class Mage_Core_Model_Resource_Type_Db_Pdo_Mysql extends Mage_Core_Model_Resource_Type_Db 5.1 //* @return Varien_Db_Adapter_Pdo_Mysql public function getConnection($config) 5.2 //* Create and return DB adapter object instance @param array $configArr Connection config @return Varien_Db_Adapter_Pdo_Mysql protected function _getDbAdapterInstance($configArr) 5.3 * Retrieve DB adapter class name * @return string */ protected function _getDbAdapterClassName() //得到----> Varien_Db_Adapter_Pdo_Mysql,做一个桥梁!!! 总体来说resource这块的功能,作为一个连接varien_db_adapter_pro_mysql的桥梁,得 到连接 又通过xml得到配置信息的表,主键等信息,为数据库操作作准备。同时有数据库事务方 面的处理。数据格式的处理
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1016656次
    • 积分:21678
    • 等级:
    • 排名:第332名
    • 原创:1081篇
    • 转载:310篇
    • 译文:3篇
    • 评论:77条
    YII2 学习教程
    博客专栏
    Yii2

    文章:7篇

    阅读:9223
    最新评论