MagentoModels and ORM Basics(summary)

本文介绍了Magento框架中对象关系映射(ORM)的基本概念,包括基本模型、EAV模型及集合的使用方式。详细解释了如何实例化模型、资源模型配置及Magento模型支持的CRUD操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Object Relational Mapping (ORM)

Most Magento Models can categorized in one of two way.There’s a basic,ActiveRecord-like/one-object-one-table Model, andthere’s also anEntity Attribute Value (EAV) Model. There’s alsoModelCollections.

Collections arePHP objects used to hold a number of individual Magento Model instances.

Magento Models don’t contain any code for connectingto the database.

When you instantiate a Model inMagento, you make a call like this

$model= Mage::getModel('weblog/blogpost');

The first part of the URI you pass into get Model istheModelGroup Name.The second part of the URI is the lowercase version of yourModel name.

All basic Models should extendtheMage_Core_Model_Abstract class. Thisabstract class forces you to implement a single method named_construct (NOTE: this is not PHP’sconstructor__consutrct).This method should call the class’s _init method with the same identifying URIyou’ll be using in theMage::getModel method call.

All Magento Models inherit from the the Varien_Object class. This class is partof the Magento system library andnot part ofany Magento core module.

resourcemodels are configured in the same section of the XML config as normal Models.

NOTE: Magento implements all magic functionality in the__call method.

CRUD: MagentoModels support the basicCreate, Read, Update, and Delete functionalityof CRUD withload,save, anddelete methods.Thesave method will allow you tobothINSERT a new Model into thedatabase, orUPDATE an existing one.

Collections: Ratherthan returning a simple array of Models, each Magento Model type has a uniquecollection object associated with it. These objects implement the PHPIteratorAggregate and Countable interfaces, which means they can be passed tothe count function,and used inforeachconstructs.


Source From:http://alanstorm.com/magento_models_orm


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值