2015-09-16 15 views

Trả lời

10

Có, Trong Magento 2 có thể tạo tệp cấu hình hệ thống giống như Magento 1.x. Nhưng nó sẽ cần phải tạo ra một số tập tin khác.

Cần sử dụng tệp sau để tạo tệp.

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

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

2 tệp này quan trọng để tạo cấu hình hệ thống.

Trong system.xml tập tin

Thêm nội dung phổ biến

<?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> 

Trong acl.xml tập tin

Trong tập tin cần phải viết nội dung dưới đây

<?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> 

Sau đó, Xóa Bộ nhớ cache Magento & đăng xuất từ ​​phía quản trị viên. Sau đó, đăng nhập tại phía quản trị. Trong cửa hàng> Cấu hình bạn có thể thấy tab "Mở rộng nhà cung cấp". Khi bạn nhấp vào điều này, bạn có thể xem chi tiết về điều này.

+0

Làm việc hoàn hảo khi tôi di chuyển phần tử "nhóm" bên trong phần tử "section". Khác system.xml dẫn đến lỗi. – Gerard

Các vấn đề liên quan