php - Magento 2 : system. 自定义模块中的 xml

标签 php magento module magento2

是否可以为 Magento 2 中的模块配置添加 system.xml 文件?如果是,怎么办?

最佳答案

是的,在 magento 2 中可以创建与 Magento 1.x 相同的系统配置文件。但它需要创建一些其他文件。

需要使用下面的文件来创建。

1) app/code/Vendor/Helloworld/etc/adminhtml/system.xml

2) app/code/Vendor/Helloworld/etc/acl.xml

这 2 个文件对于创建系统配置很重要。

system.xml文件中

添加通用内容

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../Config/etc/system_file.xsd">
    <system>
        <!-- Add new Tab -->
        <tab id="vendor" translate="label" sortOrder="300">
            <label>Vendor Extension</label>
        </tab>
        <section id="helloworld" translate="label" type="text" sortOrder="140" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>Helloworld</label>
            <tab>vendor</tab>
            <!-- resource tag name which we have to defined in the acl.xml -->
            <resource>Vendor_Helloworld::config_helloworld</resource>
            <group id="general" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>General Options</label>
                <field id="active" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Enabled</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                </field>
            </group>
        </section>
    </system>
</config>

acl.xml文件中

在文件中需要写入以下内容

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Acl/etc/acl.xsd">
    <acl>
        <resources>
            <resource id="Magento_Backend::admin">
                <resource id="Magento_Backend::stores">
                    <resource id="Magento_Backend::stores_settings">
                        <resource id="Magento_Config::config">
                            <!-- this resource id we can use in system.xml for section -->
                            <resource id="Vendor_Helloworld::config_helloworld" title="Helloworld Section" sortOrder="80" />
                        </resource>
                    </resource>
                </resource>
            </resource>
        </resources>
    </acl>
</config>

之后,清除 magento 缓存并从管理员端注销。然后在管理员端登录。在商店 > 配置中,您可以看到“供应商扩​​展”选项卡。当您单击它时,您可以看到它的详细信息。

关于php - Magento 2 : system. 自定义模块中的 xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32614392/

相关文章:

php - 如何循环遍历数组并在到达末尾时重新开始?

php - 对 WooCommerce 中的非 "on sale"商品应用欢迎折扣

php - PHP 中 Db 抽象的职责从哪里开始和结束?

css - Magento 交易电子邮件中的 email-inline.css 不起作用

haskell - 类型级程序的分层模块名称

module - 从 Rust 中同一类的另一个静态方法引用静态方法的最佳方法是什么?

php - 多语言网站 - PHP 类 - 正确的做法是什么?

magento - 如何在 Magento 中获取送货地址和订单状态?

php - 为什么 Magento 这么慢?

module - 无法从 node_modules typescript 导入 react-tap-event-plugin