Magento-根据环境加载local.xml [英] Magento - Load local.xml based on environment
问题描述
我想拥有3个app/etc/local.xml
文件-称它们为local.xml staging.xml和live.xml.
I want to have 3 app/etc/local.xml
files - call them local.xml staging.xml and live.xml.
我想基于我在虚拟主机或htaccess中设置的环境变量来加载这些文件.这样,我可以拥有单独的数据库等,但是可以在svn下保留1个代码库.
I want to load these based on an environment variable that I set in either the vhosts or the htaccess. This way I can have seperate databases etc but 1 codebase that I can keep under svn.
实现此目标的最佳方法是什么?
What would be the best way to achieve this?
推荐答案
local.xml
在多个Magento文件中被硬编码.
local.xml
is hardcoded in multiple Magento files.
因此,如果要为此实现自己的文件名选择,则必须分别覆盖几个核心类/方法/函数.
So if you want to implement your own file name selection for this, you'd have to override several core classes/methods/functions respectively.
对local.xml
*的扫描显示-除其他外-您必须修改/app/Mage.php
.那是因为您不能覆盖Mage
(这是一个final
类).
A scan for local.xml
* shows that - amongst other things - you'd have to modify /app/Mage.php
. That's because you cannot override Mage
(it's a final
class).
请注意,可以修改/app/Mage.php
,但是每次升级到下一个Magento版本都会覆盖您的更改.
Be aware that modifying /app/Mage.php
is possible, but every upgrade to the next Magento version will overwrite your changes.
如果可以忍受,您还必须至少覆盖
If you can live with that, you'd additionally have to override at least
Mage_Core_Model_Config
Mage_Core_Model_Layout_Update
也许还有
Mage_Install_Model_Installer_Config
Mage_Adminhtml_Block_Notification_Security (1.5.1)
根据您的需求.
设置文件名选择方法,例如在一个助手中:
Setup your file name selection method, e.g. in a helper:
class Mynamespace_Mymodule_Helper_Data extends Mage_Core_Helper_Data
{
public function getLocalXMLFileName()
{
return getenv('MY_XML') . 'xml';
}
}
在您覆盖的核心类中,只需调用您的辅助方法,例如改变
In your overridden core classes just call your helper method, e.g. change
$updateFiles[] = 'local.xml';
到
$updateFiles[] = Mage::helper('mymodule')->getLocalXMLFileName();
*我只扫描了1.3.2.x,1.5.1和1.8.1.0.在其他版本中,更多/更少的类可能会受到影响.
* I only scanned 1.3.2.x, 1.5.1 and 1.8.1.0. In other versions more/less classes maybe affected.
1.3.2.x:
./app/code/core/Mage/Install/Model/Installer/Config.php:49:
$this->_localConfigFile = Mage::getBaseDir('etc').DS.'local.xml';
./app/code/core/Mage/Core/Model/Layout/Update.php:283:
$updateFiles[] = 'local.xml';
./app/code/core/Mage/Core/Model/Config.php:214:
$localConfigLoaded = $this->loadFile($etcDir.DS.'local.xml');
./app/code/core/Mage/Core/Model/Config.php:248:
$configFile = $etcDir.DS.'local.xml';
./app/Mage.php:521:
$localConfigFile = self::getRoot() . DS . $etcDir . DS . 'local.xml';
1.5.1:
./app/code/core/Mage/Install/Model/Installer/Config.php:49:
$this->_localConfigFile = Mage::getBaseDir('etc').DS.'local.xml';
./app/code/core/Mage/Core/Model/Layout/Update.php:418:
$updateFiles[] = 'local.xml';
./app/code/core/Mage/Core/Model/Config.php:280:
if (in_array($etcDir.DS.'local.xml', $files)) {
./app/code/core/Mage/Core/Model/Config.php:322:
$this->_isLocalConfigLoaded = $mergeConfig->
loadFile($this->getOptions()->getEtcDir().DS.'local.xml');
./app/code/core/Mage/Adminhtml/Block/Notification/Security.php:36:
private $_filePath = 'app/etc/local.xml';
./app/Mage.php:671:
$localConfigFile = self::getRoot() . DS . $etcDir . DS . 'local.xml';
./errors/processor.php:34:
const MAGE_ERRORS_LOCAL_XML = 'local.xml';
1.8.1.0:
./app/code/core/Mage/Install/Model/Installer/Config.php:49:
$this->_localConfigFile = Mage::getBaseDir('etc') . DS . 'local.xml';
./app/code/core/Mage/Install/Model/Installer/Config.php:103:
$template = file_get_contents(Mage::getBaseDir('etc') . DS . 'local.xml.template');
./app/code/core/Mage/Core/Model/Config.php:280:
if (in_array($etcDir.DS.'local.xml', $files)) {
./app/code/core/Mage/Core/Model/Config.php:324:
$this->_isLocalConfigLoaded =
$mergeConfig->loadFile($this->getOptions()->getEtcDir().DS.'local.xml');
./app/code/core/Mage/Core/Model/Layout/Update.php:311:
// $updateFiles[] = 'local.xml';
./app/code/core/Mage/Core/Model/Layout/Update.php:431:
$updateFiles[] = 'local.xml';
./app/code/core/Mage/Adminhtml/Block/Notification/Security.php:36:
private $_filePath = 'app/etc/local.xml';
./app/Mage.php:762:
$localConfigFile = $etcDir . DS . 'local.xml';
./errors/processor.php:34:
const MAGE_ERRORS_LOCAL_XML = 'local.xml';
这篇关于Magento-根据环境加载local.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!