Magento 实时和暂存的不同配置文件

发布于 2024-10-29 13:59:31 字数 156 浏览 1 评论 0原文

网站的 live、staging 和 dev 版本是否可以有不同的 config.xml 文件。

我认为应该有一个 live.xml、local.xml 和 staging.xml,这些应该设置一次,然后通过 htaccess 环境变量或其他东西进行控制

这可能吗?

Is it possible to have different config.xml files for live, staging and dev versions of the site.

Im thinking that there should be a live.xml, local.xml and staging.xml and these should be set up once and then controlled via htaccess environment variable or something

Is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陈甜 2024-11-05 13:59:33

不,Magento 不支持开箱即用的功能,而且据我所知,没有任何模块可以提供此功能。

如果您愿意,您可以实现此版本。 Magento 的所有配置文件都是(或者应该是,别让我坚持)通过 Mage_Core_Model_Config 类加载。

#File: app/code/core/Mage/Core/Model/Config.php
public function loadModulesConfiguration($fileName, $mergeToObject = null, $mergeModel=null)
{
    $disableLocalModules = !$this->_canUseLocalModules();

    if ($mergeToObject === null) {
        $mergeToObject = clone $this->_prototype;
        $mergeToObject->loadString('<config/>');
    }
    if ($mergeModel === null) {
        $mergeModel = clone $this->_prototype;
    }
    $modules = $this->getNode('modules')->children();
    foreach ($modules as $modName=>$module) {
        if ($module->is('active')) {
            if ($disableLocalModules && ('local' === (string)$module->codePool)) {
                continue;
            }
            $configFile = $this->getModuleDir('etc', $modName).DS.$fileName;
            if ($mergeModel->loadFile($configFile)) {
                $mergeToObject->extend($mergeModel, true);
            }
        }
    }
    return $mergeToObject;
}

您可以为此模型创建一个类重写,该重写将根据环境更改 $filename,然后加载适当的配置文件。

虽然这是一个有趣的想法,但我认为这不是一个好主意。环境差异应该在部署级别上处理,并且模块的 config.xml 文件中无论如何都不应该包含任何特定于环境的信息。特定于环境的信息保存在一个位置

app/etc/local.xml

您的构建/部署系统应根据需要根据您要部署到的环境修改 local.xml。

No, nothing supports this out of the box with Magento, and there's no module I know of that offers this functionality.

You could implement a version of this if you wanted to. All of Magento's config files are (or should be, don't hold me to it) loaded via the Mage_Core_Model_Config class.

#File: app/code/core/Mage/Core/Model/Config.php
public function loadModulesConfiguration($fileName, $mergeToObject = null, $mergeModel=null)
{
    $disableLocalModules = !$this->_canUseLocalModules();

    if ($mergeToObject === null) {
        $mergeToObject = clone $this->_prototype;
        $mergeToObject->loadString('<config/>');
    }
    if ($mergeModel === null) {
        $mergeModel = clone $this->_prototype;
    }
    $modules = $this->getNode('modules')->children();
    foreach ($modules as $modName=>$module) {
        if ($module->is('active')) {
            if ($disableLocalModules && ('local' === (string)$module->codePool)) {
                continue;
            }
            $configFile = $this->getModuleDir('etc', $modName).DS.$fileName;
            if ($mergeModel->loadFile($configFile)) {
                $mergeToObject->extend($mergeModel, true);
            }
        }
    }
    return $mergeToObject;
}

You could create a class rewrite for this model that would alter the $filename based on environment, and then load the appropriate configuration file.

While it's an interesting idea, I don't think it's a good one. Differences in environment is something that should be handled on a deployment level, and a module's config.xml file shouldn't have any environment specific information in it anyways. Environment specific information is kept in one location

app/etc/local.xml

Your build/deploy system should modify local.xml as needed depending on which environment you're deploying to.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文