Php 从Magento 2中的配置路径获取system.xml中的后端模型

Php 从Magento 2中的配置路径获取system.xml中的后端模型,php,magento,magento2,Php,Magento,Magento2,我正在尝试从system.xml获取后端模型类名 现在我正在使用这个代码 magento/app/code/Company/Sso/etc/adminhtml/system.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:e

我正在尝试从system.xml获取后端模型类名 现在我正在使用这个代码

magento/app/code/Company/Sso/etc/adminhtml/system.xml

<?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>
    <section id="admin">
        <group id="sso_saml" translate="label" sortOrder="100" showInDefault="1" showInWebsite="0" showInStore="0" >
            <label>Single Sign on(SAML)</label>
            <field id="is_enabled" translate="label comment" type="select" sortOrder="0" showInDefault="1" showInWebsite="0" showInStore="0">
                <label>Is Enabled SAML</label>
                <comment>Enable Single Sign On</comment>
                <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
            </field>
        </group>
    </section>
</system>
输出:

{"id":"is_enabled","path":"admin/sso_saml","_elementType":"field"}

但是我需要source\u model,有人能帮忙吗?

您需要在adminhtml区域中才能加载其余的数据: e、 g


如果需要,您可以使用
\Magento\Framework\App\State::emulateAreaCode
从非管理员上下文中获取数据。

以下是实现Matt解决方案后的完整解决方案

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$appState = $objectManager->get('Magento\Framework\App\State');
$field = $appState->emulateAreaCode('adminhtml', function($path){
    $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $appState = $objectManager->get('Magento\Framework\App\State');
    $appState->setAreaCode('adminhtml');
    $field = $objectManager->create('Magento\Config\Model\Config\Structure')
        ->getElementByConfigPath($path->getPath());
    return $field;
}, [$path]);

$value = $path->getData()['backend_model'];

是否要从
admin/sso\u saml/is\u enabled
获取所选值?否。我需要源\u模型或后端\u模型。在这种情况下,我需要源模型值“Magento\Config\model\Config\Source\Yesno”,谢谢Matt。你的解决办法奏效了。。但我不得不使用仿效
<?php
require __DIR__ . '/app/bootstrap.php';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$appState = $objectManager->get('Magento\Framework\App\State');
$appState->setAreaCode('adminhtml');
$field = $objectManager->create('Magento\Config\Model\Config\Structure')->getElementByConfigPath('customer/create_account/auto_group_assign');
echo $field->getData()['source_model'];
> Magento\Config\Model\Config\Source\Yesno
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$appState = $objectManager->get('Magento\Framework\App\State');
$field = $appState->emulateAreaCode('adminhtml', function($path){
    $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $appState = $objectManager->get('Magento\Framework\App\State');
    $appState->setAreaCode('adminhtml');
    $field = $objectManager->create('Magento\Config\Model\Config\Structure')
        ->getElementByConfigPath($path->getPath());
    return $field;
}, [$path]);

$value = $path->getData()['backend_model'];