- 在xml文件中增加配置项和值
- 控制 website/stores/store views 的配置
- 为不同的store设置不同的配置
提示: magento在运行时会将每一个不同module的config.xml文件融合成为一个很大的全局config.xml文件。
xml内容结构
< config >...根节点为 config,以下是全部有可能出现的二级节点: < default > ... 指明该配置项的应用范围为全部store均可用 < global > ... 指明该配置项的应用范围为全局全站可用 < modules > ... 指明某个模块的基本配置 < admin > ... 指明模块的admin路由,后台的属性,fieldset < adminhtml > ... < install > ... < frontend > ... < websites > ... < stores > ... 可指明对某个store的配置 < /config >
获取某项配置的值:
$store->getConfig($path) 或者 Mage::getStoreConfig($path [, $store]);
$store 这个变量可以是 store 的 code或ID
获取某项配置是否不为空,返回值为 true / false:
Mage::getStoreConfigFlag($path [, $store]);
$store 这个变量可以是 store 的 code或ID
获取某个配置项的整个节点(Simple_Xml):
Mage::getConfig()->getNode($path [, $scope]);
$scope 通常是指一个范围,website或store
像以下这个配置, < default > 是针对全部store而设置的, stroe/french这个结点是只为 store code为french的店铺而设置的。
< default > < abc >< efg >999< /efg >< /abc > < /default > < stores > < french > < abc >< efg >888< /efg >< /abc > < /french > < /stores >
所以,当你用$b = Mage::getStoreConfig('abc/efg');时,如果当前店铺的store view是英语,那么你获得的配置值就是 999 (从default那里得到),如果你把店铺的view切换到 french时,再运行 这句,那么你得到的值就是888