Terry - 专注外贸B2C

GitHub地址:https://github.com/fancyecommerce

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

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_Modelcatalog_resource_eav_mysql4Mage_Catalog_Model_Resource_Eav_Mysql4 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得到配置信息的表,主键等信息,为数据库操作作准备。同时有数据库事务方 面的处理。数据格式的处理
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/terry_water/article/details/6141662
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭