2015-09-16 3 views

ответ

10

Да, в 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 cache & выход из стороны администратора. Затем войдите в систему со стороны администратора. В магазине> Конфигурация вы можете увидеть вкладку «Расширение поставщика». Когда вы нажмете на это, вы сможете увидеть детали этого.

+0

Работал отлично, когда я переместил элемент «группа» внутри элемента «section». В противном случае system.xml привел к ошибке. – Gerard

Смежные вопросы