Magento 2.0.2 我正在尝试添加新的用户角色,但是当我转到“角色资源”选项卡时,它不显示资源树。我没有显示任何错误。下一步是什么来尝试找出不显示的原因。

笔记 : 我以管理员身份登录

截图:enter image description here

有帮助吗?

解决方案

经过长期研究,我能解决这个问题。 错误是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_Adminhtml::admin">
            <resource id="Company_Module::" title="test" sortOrder="100"/>
        <!--AddMenuAcl-->
        </resource>
    </resources>
</acl>
</config>
.

替换为:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
<acl>
    <resources>
        <resource id="Magento_Backend::admin">
            <resource id="Company_module::test" title="test module" sortOrder="100"/>
            <!--AddMenuAcl-->
        </resource>
    </resources>
</acl>
</config>
.

检查此外:

 <?xml version="1.0"?>
 <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"             xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
<acl>
    <resources>
        <resource id="Magento_Adminhtml::admin">
        </resource>
    </resources>
</acl>
.

如果没有使用资源,请注释:

    <?xml version="1.0"?>
     <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
<acl>
    <resources>
        <!--<resource id="Magento_Adminhtml::admin">
        </resource>-->
    </resources>
</acl>
.

其他提示

我确认了曼鱼报告的内容。问题位于ACL.xml文件中。 在我的情况下(magento 2.1)我有以下acl.xml:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
<acl>
    <resources>
        <resource id="Magento_Backend::all_elements" title="Ves ALl">
                <resource id="Ves_All::ves_all" title="Ves All" sortOrder="10">
                </resource>
        </resource>
        <resource id="Magento_Backend::admin">
            <resource id="Magento_Backend::stores">
                <resource id="Magento_Backend::stores_settings">
                    <resource id="Magento_Config::config">
                        <resource id="Ves_All::config" title="Ves All - Config Settings" />
                    </resource>
                </resource>
            </resource>
        </resource>
    </resources>
</acl>
.

我已删除如下所示的第一个资源:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
<acl>
    <resources>
        <!-- <resource id="Magento_Backend::all_elements" title="Ves ALl">
                <resource id="Ves_All::ves_all" title="Ves All" sortOrder="10">
                </resource>
        </resource>  -->
        <resource id="Magento_Backend::admin">
            <resource id="Magento_Backend::stores">
                <resource id="Magento_Backend::stores_settings">
                    <resource id="Magento_Config::config">
                        <resource id="Ves_All::config" title="Ves All - Config Settings" />
                    </resource>
                </resource>
            </resource>
        </resource>
    </resources>
</acl>
.

且神奇地在admin侧面再次出现资源树(刷新缓存后)!

这是临时解决方案为我工作。 D:\ xampp \ htdocs \ project \ vendor \ magento \ module-user \ block \ role \ tab \ edit.php

    <?php
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Magento\User\Block\Role\Tab;

use Magento\Framework\App\ObjectManager;
use Magento\User\Controller\Adminhtml\User\Role\SaveRole;

/**
 * Rolesedit Tab Display Block.
 *
 */
class Edit extends \Magento\Backend\Block\Widget\Form implements \Magento\Backend\Block\Widget\Tab\TabInterface
{
    /**
     * @var string
     */
    protected $_template = 'role/edit.phtml';

    /**
     * Root ACL Resource
     *
     * @var \Magento\Framework\Acl\RootResource
     */
    protected $_rootResource;

    /**
     * Rules collection factory
     *
     * @var \Magento\Authorization\Model\ResourceModel\Rules\CollectionFactory
     */
    protected $_rulesCollectionFactory;

    /**
     * Acl builder
     *
     * @var \Magento\Authorization\Model\Acl\AclRetriever
     */
    protected $_aclRetriever;

    /**
     * Acl resource provider
     *
     * @var \Magento\Framework\Acl\AclResource\ProviderInterface
     */
    protected $_aclResourceProvider;

    /** @var \Magento\Integration\Helper\Data */
    protected $_integrationData;

    /**
     * Core registry
     *
     * @var \Magento\Framework\Registry
     */
    protected $coreRegistry = null;

    /**
     * @param \Magento\Backend\Block\Template\Context $context
     * @param \Magento\Framework\Acl\RootResource $rootResource
     * @param \Magento\Authorization\Model\ResourceModel\Rules\CollectionFactory $rulesCollectionFactory
     * @param \Magento\Authorization\Model\Acl\AclRetriever $aclRetriever
     * @param \Magento\Framework\Acl\AclResource\ProviderInterface $aclResourceProvider
     * @param \Magento\Integration\Helper\Data $integrationData
     * @param array $data
     */
    public function __construct(
        \Magento\Backend\Block\Template\Context $context,
        \Magento\Authorization\Model\Acl\AclRetriever $aclRetriever,
        \Magento\Framework\Acl\RootResource $rootResource,
        \Magento\Authorization\Model\ResourceModel\Rules\CollectionFactory $rulesCollectionFactory,
        \Magento\Framework\Acl\AclResource\ProviderInterface $aclResourceProvider,
        \Magento\Integration\Helper\Data $integrationData,
        array $data = []
    ) {
        $this->_aclRetriever = $aclRetriever;
        $this->_rootResource = $rootResource;
        $this->_rulesCollectionFactory = $rulesCollectionFactory;
        $this->_aclResourceProvider = $aclResourceProvider;
        $this->_integrationData = $integrationData;
        parent::__construct($context, $data);
    }

    /**
     * Set core registry
     *
     * @param \Magento\Framework\Registry $coreRegistry
     * @return void
     * @deprecated
     */
    public function setCoreRegistry(\Magento\Framework\Registry $coreRegistry)
    {

        $this->coreRegistry = $coreRegistry;
    }

    /**
     * Get core registry
     *
     * @return \Magento\Framework\Registry
     * @deprecated
     */
    public function getCoreRegistry()
    {

        if (!($this->coreRegistry instanceof \Magento\Framework\Registry)) {
            return \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\Framework\Registry');
        } else {
            return $this->coreRegistry;
        }
    }

    /**
     * Get tab label
     *
     * @return \Magento\Framework\Phrase
     */
    public function getTabLabel()
    {
        return __('Role Resources');
    }

    /**
     * Get tab title
     *
     * @return string
     */
    public function getTabTitle()
    {
        return $this->getTabLabel();
    }

    /**
     * Whether tab is available
     *
     * @return bool
     */
    public function canShowTab()
    {
        return true;
    }

    /**
     * Whether tab is visible
     *
     * @return bool
     */
    public function isHidden()
    {
        return false;
    }

    /**
     * Check if everything is allowed
     *
     * @return bool
     */
    public function isEverythingAllowed()
    {
        $selectedResources = $this->getSelectedResources();
        $id = $this->_rootResource->getId();
        return in_array($id, $selectedResources);
    }

    /**
     * Get selected resources
     *
     * @return array|mixed|\string[]
     */
    public function getSelectedResources()
    {
        $selectedResources = $this->getData('selected_resources');
        if (empty($selectedResources)) {
            $allResource = $this->getCoreRegistry()->registry(SaveRole::RESOURCE_ALL_FORM_DATA_SESSION_KEY);
            if ($allResource) {
                $selectedResources = [$this->_rootResource->getId()];
            } else {
                $selectedResources = $this->getCoreRegistry()->registry(SaveRole::RESOURCE_FORM_DATA_SESSION_KEY);
            }

            if (null === $selectedResources) {
                $rid = $this->_request->getParam('rid', false);
                $selectedResources = $this->_aclRetriever->getAllowedResourcesByRole($rid);
            }

            $this->setData('selected_resources', $selectedResources);
        }
        //var_dump($selectedResources); die();
        return $selectedResources;
    }

    /**
     * Get Json Representation of Resource Tree
     *
     * @return array
     */
    public function getTree()
    {
        $resources = $this->_aclResourceProvider->getAclResources();
        $rootArray = $this->_integrationData->mapResources(
            //isset($resources[1]['children']) ? $resources[1]['children'] : []; //comment this line
            isset($resources[2]['children']) ? $resources[2]['children'] : []
        ); //use this line
        return $rootArray;
    }
}
.

请参考最后的方法用评论。

代码以角色资源中的模块拆除:

 <?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
<acl>
    <resources>
        <resource id="Magento_Backend::admin">
            <resource id="Ipragmatech_Bannerblock::ipragmatech_indexindex"
                title="Banner Block" sortOrder="40">
                <resource id="Ipragmatech_Bannerblock::slider" title="Slider"
                    sortOrder="10" />
            </resource>
            <!--AddMenuAcl -->
            <resource id="Magento_Backend::stores">
                <resource id="Magento_Backend::stores_settings">
                    <resource id="Magento_Config::config">
                        <resource id="Ipragmatech_Bannerblock::config_bannerblock"
                            title="Banner Block" sortOrder="50" />
                    </resource>
                </resource>
                <!-- <resource id="Magento_Backend::stores_other_settings"> <resource 
                    id="Magento_Customer::group" title="Customer Groups" sortOrder="10" /> </resource> -->
            </resource>
        </resource>
    </resources>
</acl>
.

 <resource id="Ipragmatech_Bannerblock::config_bannerblock"
                        title="Banner Block" sortOrder="50" />
                </resource>
.

应该与system.xml相同。

vendor/magento/module-user/Block/Role/Tab/edit.php

直接转205号线

替换为

isset($resources[2]['children']) ? $resources[2]['children'] : []

问题解决了。

许可以下: CC-BY-SA归因
scroll top