magento xml配置详解(1)

  • 在xml文件中增加配置项和值
  • 控制 website/stores/store views 的配置
  • 为不同的store设置不同的配置
提示: magento在运行时会将每一个不同moduleconfig.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。



----------
**config.xml** 

<?xml version="1.0"?>  
<config>  
    <modules><!-- 代表模块 -->  
        <SomeOption_ExtraConfig><!-- 包_模块 -->  
            <version>1.0.0</version><!-- 版本号 编写升级包时需要用到 -->  
        </SomeOption_ExtraConfig>  
    </modules>  
    <global>  
        <helpers><!-- 定义帮助类 -->  
            <extraconfig><!-- 模块名注意一般都使用小写 -->  
                <class>SomeOption_ExtraConfig_Helper</class><!-- 帮助类中类名的前缀,后台建立新的标签时必须的 -->  
            </extraconfig>  
        </helpers>  
        <blocks><!-- 定义Block类 -->  
            <extraconfig><!-- 模块名注意一般都使用小写 -->  
                <class>SomeOption_ExtraConfig_Block</class><!-- Block类的前缀 -->  
            </extraconfig>  
        </blocks>  
    </global>  
</config>

system.xml

<config>  
    <tabs><!-- 注册一个标签 在后台config左边的分类设置栏 -->  
        <someoption translate="label" module="extraconfig"><!-- someoption节点的唯一ID可以随便取,保持唯一性即可,module代表这个节点属于哪个模块的 -->  
            <label>Some Options</label><!-- 节点所要显示出来的名字 -->  
            <sort_order>1</sort_order><!-- 标签显示的位置 -->  
        </someoption>  
    </tabs>  
    <sections><!-- 标签的选项 -->  
        <imagescroll translate="label" module="extraconfig"><!-- imagescroll选项的唯一标识,可以随便取,保持唯一性即可 -->  
            <label>ImageScroll Setting</label><!-- 选项名 -->  
            <tab>someoption</tab><!-- 所属标签 -->  
            <frontend_type>text</frontend_type>  
            <sort_order>40</sort_order>  
            <show_in_default>1</show_in_default><!-- 是否显示 -->  
            <show_in_website>1</show_in_website><!-- 是否显示 -->  
            <show_in_store>1</show_in_store><!-- 是否显示 -->  
            <groups><!-- 定义右边的一些选项及设置 -->  
                <imagescrolloption translate="label"><!-- imagescrolloption随便取,保持唯一 -->  
                    <label>Uploade Images</label>  
                    <frontend_type>text</frontend_type>  
                    <sort_order>100</sort_order>  
                    <show_in_default>1</show_in_default>  
                    <show_in_website>1</show_in_website>  
                    <show_in_store>1</show_in_store>  
                    <fields><!-- 一些设置 -->  
                        <imagesupload0>  
                            <label>Image One:</label>  
                            <!--  
                                frontend_type可以使用以下的选项:  
                                allowspecific  
                                export  
                                image  
                                import  
                                label  
                                multiselect  
                                obscure  
                                password  
                                select  
                                text  
                                textarea  
                                time  
                            -->  
                            <frontend_type>image</frontend_type><!-- 选项的类型 -->  
                            <backend_model>adminhtml/system_config_backend_image</backend_model><!-- 上载文件所使用的系统模块 -->  
                            <upload_dir config="system/filesystem/media" scope_info="1">ebay/scroll</upload_dir><!-- 上载到的位置 -->  
                            <base_url type="media" scope_info="1">ebay/scroll</base_url><!-- <img标签中src所使用的路径 -->  
                            <sort_order>1</sort_order>  
                            <show_in_default>1</show_in_default>  
                            <show_in_website>1</show_in_website>  
                            <show_in_store>1</show_in_store>  
                        </imagesupload0>  
                    </fields>  
                </imagescrolloption>  
            </groups>  
        </imagescroll>  
    </sections>  
</config> 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值