Magento安装完成后一定有一些设置好的核心配置。当你从后台面板更新这些值的时候,数据会被保存到core_config_data到这张数据表。这看起来很重要,也是你不会去碰触的,是嘛?在有些情况下,你想要用代码直接修改设置,这篇文章就将演示如何去做。

假设我们想将“demo store notice” (on/off)的值从0改为1。你可以打开你的数据库,进入“core_config_data“表,改变这个数据的值,然后保存。好吧,下面就是我要讲的代码,你可以在你代码的任何一位置调用它:

$alwaylySwitch = new Mage_Core_Model_Config();
/*
*turns notice on
*/
$alwaylySwitch ->saveConfig('design/head/demonotice', "1", 'default', 0);
/*
*turns notice off
*/
$alwaylySwitch ->saveConfig('design/head/demonotice', "0", 'default', 0);

实现这一神奇功能的代码是:

class Mage_Core_Model_Config
{
	.
	.
	.
 
	/**
     * Save config value to DB
     *
     * @param string $path
     * @param string $value
     * @param string $scope
     * @param int $scopeId
     * @return Mage_Core_Store_Config
     */
    public function saveConfig($path, $value, $scope = 'default', $scopeId = 0)
    {
        $resource = $this->getResourceModel();
        $resource->saveConfig(rtrim($path, '/'), $value, $scope, $scopeId);
 
        return $this;
    }
 
	.
	.
	.
}

360magento提供专业的基于magento系统的电商网站开发服务,如有需求或相关咨询,请与我们联系