Magento - module conventions mysql4 or resource

Go To StackoverFlow.com

7

There seems to be two styles of folder structure in the core Magento when it comes to resources. There are quite a lot using the mysql4 folder and other simple using Resource folder.

I.e. install script would live here: Mycompany_Mymodule_Model_Resource_Setup.

Is there a reason for this, legacy or otherwise - or is this simply a coding style between different core developers?

2012-04-03 20:09
by Marty Wallace


16

First: Magento's folder structure exists only because of its autoloader's implementation. If you try to derive too much meaning from where a file is placed in Magento you'll go mad, and different modules seem to follow different conventions. The autoloader will look for

Mage_Core_Model_Foo_Bar

in

Mage/Core/Model/Foo/Bar.php

So I'll be talking about naming conventions below, which will indirectly address why a file is in a particular folder.

Originally all database resource were named with the Mysql4 convention. I've talked to a few of the original developers, and the intention was to denote that the resource was for the then "standard" Mysql 4 database. If a resource used a specific feature of say, Mysql 5, then they'd have used a Mysql5 convention.

As Magento Inc. went through the usual startup churn and other developers took over where the original developers left off, the thinking changed on this. The Magento 1.6 release, which laid the groundwork for Enterprise Edition's support of multiple RDBMS, altered how these resources worked and were named.

Backwards compatibility was maintained, but most of the old Mysql4 resources were renamed to use the generic Resource, and a new method for multiple RDBMS support was introduced.

2012-04-03 21:11
by Alan Storm
Ok great - thanks Alan, i was pretty sure it would be a legacy thing - Marty Wallace 2012-04-03 21:31
Ads