php - 其他用户无法访问 Magento 2 自定义模块

标签 php xml acl magento2

我在 magento 2 管理员中有简单的网格列表自定义模块,但我无法在其他用户然后默认管理员中访问它,

这是我的文件

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="Spaarg_Tables::tables" title="tables" sortOrder="100"/>
 <!--AddMenuAcl-->
            </resource>
        </resources>
    </acl>
</config>

菜单.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2015 Spaarg. All rights reserved.
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../Backend/etc/menu.xsd">
    <menu>
        <add id="Spaarg_Tables::spaarg_tablesgrid_index" title="Tables" module="Spaarg_Tables"  sortOrder="20" dependsOnModule="Spaarg_Tables" action="tables/tablesgrid/index" resource="Spaarg_Tables::spaarg_tablesgrid_index"/>
<!--AddMenu-->
    </menu>
</config>

系统.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../Config/etc/system_file.xsd">
    <system>
        <section id="payment">
            <!-- payment-group -->
        </section>
        <section id="carriers" translate="label" type="text" sortOrder="320" showInDefault="1" showInWebsite="1" showInStore="1">
            <!-- carrier-group -->
        </section>
        <section id="tables" translate="label" type="text" sortOrder="330" showInDefault="1" showInWebsite="1" showInStore="1">
            <!-- tables-group -->
        </section>
    </system>
</config>

这是我的 Controller 索引.php

<?php
namespace Spaarg\Tables\Controller\Adminhtml\TablesGrid;

use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;


class Index extends Action
{
    /**
     * @var \Magento\Framework\View\Result\PageFactory
     */
    protected $resultPageFactory;

    /**
     * @var \Magento\Backend\Model\View\Result\Page
     */
    protected $resultPage;

    /**
     * @param Context $context
     * @param PageFactory $resultPageFactory
     */
    public function __construct(
        Context $context,
        PageFactory $resultPageFactory
    )
    {
        parent::__construct($context);
        $this->resultPageFactory = $resultPageFactory;
    }

    public function execute()
    {

        $this->resultPage = $this->resultPageFactory->create();  
        $this->resultPage->setActiveMenu('Spaarg_TablesGrid::tables');
        $this->resultPage ->getConfig()->getTitle()->set((__('TablesGrid')));
        return $this->resultPage;
    }

    protected function _isAllowed()
    {
      return $this->_authorization->isAllowed('Spaarg_TablesGrid::tables');
    }

}

它显示已 checkin 我的模块的用户角色, 我是 magento 的新手,如果有人可以建议一种处理方法,那就太好了。

最佳答案

<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="Magento_Backend::stores">
                    <resource id="Magento_Backend::stores_settings">
                        <resource id="Magento_Config::config">                            
                            <resource id="Spaarg_Tables::tables" title="tables" sortOrder="100"/>
                        </resource>
                    </resource>
                </resource>
            </resource>
        </resources>
    </acl>
</config>

关于php - 其他用户无法访问 Magento 2 自定义模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41038490/

相关文章:

c++ - TinyXML2 - 在 XML 中间插入元素

linux - 每个用户的 LDAP 特定 ACL

php - Windows Azure PHP 队列 REST 代理限制

php - 您是否必须在本地主机和生产环境中运行 Composer?

java - 当 XPath 使用 preceding-sibling axis 时,我想以相反的顺序返回节点?如何 ?

ios - Swift - 如何从 XML 代码动态构建 iOS 用户界面?

php - 将 foreach 循环结果作为 key php

php - 所有列都设置为相同的值

spring - 具有自定义权限的 Grails ACL

java - Spring security 在 PreAuthorize 中使用 hasPermission,仅使用一个参数