天天看點

magento xml配置詳解(1)

  • 在xml檔案中增加配置項和值
  • 控制 website/stores/store views 的配置
  • 為不同的store設定不同的配置
提示: magento在運作時會将每一個不同module的config.xml檔案融合成
為一個很大的全局config.xml檔案。
           

xml内容結構

magento xml配置詳解(1)
< config >...根節點為 config,以下是全部有可能出現的二級節點:

     < default > ... 指明該配置項的應用範圍為全部store均可用
     < global > ... 指明該配置項的應用範圍為全局全站可用
     < modules > ... 指明某個子產品的基本配置
     < admin > ... 指明子產品的admin路由,背景的屬性,fieldset
     < adminhtml > ...  
     < install > ...  
     < frontend > ...  
     < websites > ...  
     < stores > ... 可指明對某個store的配置

< /config >
           
magento xml配置詳解(1)
擷取某項配置的值:
$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
           
magento xml配置詳解(1)
magento xml配置詳解(1)
magento xml配置詳解(1)

像以下這個配置, < 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>