服务报价 | 域名主机 | 网络营销 | 软件工具| [加入收藏]
 热线电话: #
当前位置: 主页 > php教程 > magento教程 >

配置Magento文件System.xml开发详解(2)

时间:2013-12-07 23:43来源:未知 作者:最模板 点击:
这里,我们来创建一个新的 Section, 代码如下: ?xml version=1.0?configsectionstestsection translate=label module=testlabelNew Test Section/labeltabcustomer/tabsort_order130/sort_ordersh

这里,我们来创建一个新的 Section, 代码如下:

<?xml version="1.0"?>
<config>
<sections>
<testsection translate="label" module="test">
<label>New Test Section</label>
<tab>customer</tab>
<sort_order>130</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<groups>
<test translate="label">
<label>Test Group</label>
<sort_order>10</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<fields>
<patient translate="label">
<label>Sign In Gate Email Template</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_email_template</source_model>
<sort_order>3</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</patient>
</fields>
<fields>
<slider translate="label">
<label>Show Slider In Sign In Gate</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>99</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</slider>
</fields>
</test>
</groups>
</testsection>
</sections>
</config>

完成后, 你应该可以在 Customer Tab 里看到 “New Test Section”, 但还需要一步, 那就是要在 config.xml 里添加权限(ACL), 不然你点击就会发现 404 错误, 你可以看下类: Mage_Adminhtml_System_ConfigController, 在 259 行左右的 _isSectionAllowed($section) 方法, 它会检查新的 seciton 是否有权限, 如果有才会显示出来

现在在 config.xml 里的 <adminhtml> 标签中写入如下代码:

<acl>
    <resources>
        <admin<!-- acl 是基于 URL 的. 这里你可以看到 URL 是 /admin/system_config/ -->
            <children>
                <system>
                    <children>
                        <config>
                            <children>
                                <testsection translate="title" module="test"<!-- 这里就是我们创建的 section 名称 -->
                                    <title>Test Section ACL</title>  <!-- 这个 title 将显示在 User -> Roles -> Permissions  -->                                    <sort_order>99</sort_order>                                 </testsection>                            </children>                         </config>                     </children>                </system>             </children>         </admin>     </resources> </acl>

现在你登出后台, 重新登入, 新的 section 已经工作正常了

system-xml-04

标签 (Tab)

 

创建一个新的 tab, 代码如下:

<?xml version="1.0"?>
<config>
    <tabs>
        <newtab translate="label" module="customer">
            <label>New Tab</label>
            <sort_order>1</sort_order>
        </newtab>
    </tabs>
    <sections>
        <testsection translate="label" module="test">
            <class>separator-top</class>
            <label>New Test Section</label>
            <tab>newtab</tab>
            <sort_order>130</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>1</show_in_store>
            <groups>
                <test translate="label">
                    <label>Test Group</label>
                    <sort_order>10</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>
                    <fields>
                        <patient translate="label">
                            <label>Sign In Gate Email Template</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_email_template</source_model>
                            <sort_order>3</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </patient>
                    </fields>
                    <fields>
                        <slider translate="label">
                            <label>Show Slider In Sign In Gate</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                            <sort_order>99</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                       </slider>
                    </fields>
                </test>
            </groups>
        </testsection>
    </sections>
</config>

同样, 此操作也需要之前的 ACL 配置, 有些情况下会报 permission 错误, 你可以到 System -> Permission ->Roles, 点击你的角色编辑再保存

system-xml-05

为新建的文本域添加默认值

 

在 system.xml 中完成如上操作后, 我们也可以为其添加默认值, 比如说有一个 Yes/No 下拉框, 你可以在 config.xml 中添加默认值:

<default<!-- 需要直接写在 <config> 标签里 -->
    <testsection<!-- section 名 -->
        <test> <!-- group 名-->
            <patient>1</patient> <!-- field 名和值-->
            <slider>1</slider>
        </test>
    </testsection>
</default>

到这里就了解了magento的 system.xml 的基础, 在随后的章节里, 最模板会列出不同种类的文本域, 方便大家以后使用时可以直接查阅调用

(责任编辑:最模板)
顶一下
(4)
80%
踩一下
(1)
20%
------分隔线----------------------------
栏目列表
热点内容