markdown 模型和资源模型类解析步骤

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 模型和资源模型类解析步骤相关的知识,希望对你有一定的参考价值。

Resource Model Instantiation Steps
---

 1. Call to abstract factory method, e.g. Mage::getResourceModel('example/thing')
 2. Factory class name: exampel/thing
 3. Split into class group **example** and the rest **thing**
 4. Config xpath lookup: global/models/example/resourceModel
 5. Resolves to "resource class group", e.g. example_resource
 6. Config xpath lookup: global/models/example_resource/rewrite/thing
 7. If exists, use as class name. If not continue
 8. Config xpath lookup: global/models/example_resource/deprecatedNode
 9. Resolves to former (pre Magento 1.6) resource class group, e.g. example_mysql4
 10. If it exists, config xpath lookup: global/models/example_mysql4/rewrite/thing
 11. If exists, use as class name. If not continue
 12. Config xpath lookup: global/models/example_resource/class
 13. Resolves to resource class prefix, e.g. This_Example_Model_Resource
 14. Append the part of the factory class name after the slash
 15. Resolves to This_Example_Model_Resource_thing
 16. Trigger autoloader which uppercases each word
 17. Resolves to file system path This/Example/Model/Resource/Thing.php
 18. Include this file and try to instantiate the class

*Note* that the purpose of the deprecatedNode lookup on step 8 is backward compatibility for old modules that rewrite resource models using the old, pre-Magento 1.6 resource class group names. There is a node literally called "deprecatedNode". (Magento introduced multi database support and major resource layer refactoring in 1.6 (MMBD)).

*Note 2* that the same steps are true for instantiating collections, since they are also created using the Mage::getResourceModel() factory method.
Model Instantiation Steps
---

 1. Call to abstract factory method e.g. Mage::getModel('example/thing')
 2. Factory class name: example/thing
 3. Split into class group **example** and the rest **thing**
 3. Config xpath lookup: global/models/example/rewrite/thing
 4. If exists, use as class name. If not continue
 5. Config xpath lookup: global/models/example/class
 6. Resolves to model class prefix, e.g. This_Example_Model
 7. Append the part of the factory class name after the slash
 8. Resolves to This_Example_Model_thing
 9. Trigger autoloader which uppercases each word
 10. Resolves to file system path This/Example/Model/Resource/Thing.php
 11. Include this file and try to instantiate the class
Debugging (Resource) Model Instantiation
---
Follow each step manually and any bugs during (resource) model instantiation will become obvious.

Since many people find model and resource model instantiation to be one of the more challenging things in Magento 1, these are all the steps Magento does to resolve the factory name to the real PHP class name.  

To debug, simply follow each step manually until you find a non-match. This works really well in my experience.  
Less guessing, more and faster results.

In the examples I use a factory name of "example/thing".  
This is split by Magento to a *"class group"* "example and a part-after-the-slash *"thing"*.

以上是关于markdown 模型和资源模型类解析步骤的主要内容,如果未能解决你的问题,请参考以下文章

如何扩展 pimcore 对象模型和他的资源类

语义网的模型定义

2-SpringMVC-1-模型和视图

如何使用模型类在 laravel 8 资源控制器中编辑、销毁和获取单个值?

前端性能优化

Java生产消费者模型——代码解析