views:

173

answers:

1

Hey guys,

Im starting a project with Magento. Let me first say, that i come from the MS world, i have never used PHP before, and while im catching up quite rapidly i'm def a php newb.

I can't quite seem to grasp the differences between the model, resource model, resource and entity objects and how they are related in the magento architecture.

I've tried googling for days now and i have found little info, and what i have found doesn't really explain it!

+4  A: 

Magento is far from typical of PHP development and what it calls things don't always agree with what other people call them. Magento splits the model layer up into two parts as you've recognised, with the Model handling the business-logic, and the Resource part only dealing with talking to the database - the theory being that if you decided on a data-store that wasn't addressable with PDO, you'd be able to swap in a different resource to handle/loading and saving, without any of the logic that surrounds those things.

The two different types of Resource that magento does have are Entity and Mysql4 - the latter being a pretty standard table-gateway system, where the Resource maps to a table in the database, the former is a bit more complicated. In order to make it really easy for users and developers to add custom fields to things, the main parts of magento (products, customers, orders etc.) are all represented by what's known as Entity-Attribute-Value system (EAV) where rather than having a typed column per value, you have a row with a key (c.f. column name) and a value. The Entity Resources handle the mapping of these eav tables to the field-array that holds the data.

To emphasise though, this is far from typical of a PHP application and if your intention is to learn PHP, I'd pick a different system.

Greg
Thanks! So resources are very similar to a data layer in the .NET world? I'm learning PHP so that i can make magento extensions. I'm finding though, that i like its architecture and flexibility. But it serisouly lacks documentation.
IceCactus
There's a pretty good introduction to models (and other things) by the chaps at Inchoo - it's a sample extension that does nothing more than setup access to a DB table (i.e. not useful for a store, but good for developrs): http://inchoo.net/ecommerce/magento/getting-started-with-magento-orm-setting-up-the-model/
Greg