I really like the way that Magento uses code pools so that classes and functionality can be extended without actually changing the core functionality of the code.
(for those not familiar with Magento you can have the same class in the "core" code pool and the "local" code pool and when you create a class it first looks in the "local" code poo开发者_如何学运维l and if it does not exist it looks in the "core" code pool)
I know that Magneto uses the Zend Framework so I was wondering if Varien used something already inside of the Zend Framework of if they did this themselves? Or if someone knows if there is a good way to effectively do this in Zend Framework?
I dont know how Magento does that (tipp: look at their sourcecode), but you could probably achieve the same with Zend_Autoloader
, e.g. when trying to load class Foo_Bar_Baz
the autoloader will first look in Local/Foo/Bar/Baz
and if the file isn't there it will try to load from Core/Foo/Bar/Baz
.
Note: If anyone's interested, take a look at the top of
app/Mage.php
(excerpt follows) to see how this gets set. --Alan
if (defined('COMPILER_INCLUDE_PATH')) {
$appPath = COMPILER_INCLUDE_PATH;
set_include_path($appPath . PS . Mage::registry('original_include_path'));
include_once "Mage_Core_functions.php";
include_once "Varien_Autoload.php";
} else {
/**
* Set include path
*/
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'local';
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'community';
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'core';
$paths[] = BP . DS . 'lib';
$appPath = implode(PS, $paths);
set_include_path($appPath . PS . Mage::registry('original_include_path'));
include_once "Mage/Core/functions.php";
include_once "Varien/Autoload.php";
}
精彩评论