magento2 后台config配置和读取配置

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
        <tab id="Maijindou" translate="label" sortOrder="1">
            <label>Maijindou</label>
        </tab>
        <section id="Maijindou_Customer_admin" translate="label" type="text" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>会员API配置</label>
            <tab>Maijindou</tab>
            <resource>Maijindou_Customer::configurations</resource>
            <group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>基础设置</label>
                <field id="maijindou_url" translate="label" type="text" sortOrder="20" showInDefault="1"
                       showInWebsite="1" showInStore="1">
                    <label>请求地址</label>
                </field>
                <field id="maijindou_app_id" translate="label" type="text" sortOrder="20" showInDefault="1"
                       showInWebsite="1" showInStore="1">
                    <label>APP_ID</label>
                </field>
                <field id="maijindou_sc" translate="label" type="text" sortOrder="20" showInDefault="1"
                       showInWebsite="1" showInStore="1">
                    <label>SC</label>
                </field>
                <field id="page_layout" translate="label comment" type="select" sortOrder="29" showInDefault="1"
                       showInWebsite="1" showInStore="1">
                    <label>账号类型</label>
                    <source_model>Maijindou\Customer\Model\Layout</source_model>
                </field>
            </group>
        </section>
    </system>
</config>

下拉框选项
Maijindou\Customer\Model\Layou

<?php

namespace Maijindou\Customer\Model;

class Layout implements \Magento\Framework\Option\ArrayInterface{
    
    public function toOptionArray(){
        return [
            ['value' => '1', 'label' => __('手机')],
            ['value' => '2', 'label' => __('邮箱')],
        ];
    }
    
    public function toArray(){
        return [
            '1' => __('手机'),
            '2'  => __('邮箱'),
        ];
    }
}

最终呈现效果
在这里插入图片描述

获取配置信息

    public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig)
    {
        //获取后台config配置
        $this->_scopeConfig = $scopeConfig;
        $this->url = $this->_scopeConfig->getValue('Maijindou_Customer_admin/general/maijindou_url', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
       
    }

查看更多

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值