我學習Magento 2,在2周內,出現了這樣的任務。
我需要在銷售側邊欄添加一個自定義標簽,也許有人已經遇到了這樣的任務?
CodePudding
要在Magento 2管理中添加一個帶有默認登陸頁面的選單項,請添加這些檔案并根據自己的需要進行調整。這將在銷售選單標簽下創建一個自定義選單項,并有一個示例頁面。
app/code/Company/Module/registration.php
<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE。
'Company_Module'。
__DIR__.
);
app/code/Company/Module/etc/module.xml
<?xml version="1.0"? >
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/span>
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">/span>
<module name="Company_Module"/span>/>
</config>/span>
app/code/Company/Module/etc/acl.xml
<? xml version="1.0"? >
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/span>
xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd"/span>>
<acl>/span>
<resources>/span>
<resource id="Magento_Backend::admin"/span>>
<resource id="Magento_Sales::sales"/span>>
<resource id="Magento_Sales::sales_operation"/span>>
<resource id="Company_Module:: custommenu" title="Custom Menu" sortOrder="10"/>
</resource>/span>
</resource>/span>
</resource>/span>
</resources>/span>
</acl>/span>
</config>
app/code/Company/Module/etc/adminhtml/menu.xml
<?xml version="1.0"? >
<config xmlns:xsi="http://www.w3. org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
<menu>
<add id="Company_Module::custommenu"
title="自定義選單"
module="Company_Module"/span>
sortOrder="100"
parent="Magento_Sales::sales_operation"。
action="custommenu/index/index"。
resource="Company_Module::custommenu"。
/>
</menu>
</config>
app/code/Company/Module/etc/adminhtml/routes.xml
<?xml version="1.0"? >
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/span>
xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">/span>
<router id="admin">/span>
< 路線 id="custommenu" frontName="custommenu">
<module name="Company_Module"/>/span>
</route>/span>
</router>/span>
</config>
app/code/Company/Module/Controller/Adminhtml/Index/Index.php
<?php
namespace CompanyModule控制器AdminhtmlIndex。
class Index extends MagentoBackendAppAction
{
protected $resultPageFactory = false;
public function __construct()
MagentoBackendAppActionContext $context,
MagentoFrameworkViewResultPageFactory $resultPageFactory。
) {
parent::__construct($context)。
$this-> resultPageFactory = $resultPageFactory;
}
public function execute()
{
$resultPage = $this-> resultPageFactory-> create();
$resultPage->setActiveMenu('Company_Module::custommenu')。
$resultPage->getConfig()->getTitle()->prepend(__('Custom Menu') 。)
return $resultPage。
}
protected function _isAllowed(>/span>)
{
return $this->_authorization->isAllowed('Company_Module::custommenu') 。
}
app/code/Company/Module/view/adminhtml/layout/custommenu_index_index.xml
<?xml version="1.0"? >
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/span>
xsi:noNamespaceSchemaLocation="urn:Magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="MagentoBackendBlockTemplate"/span> template="Company_Module: :content. phtml"/>
</referenceContainer>/span>
</body>
</page>
app/code/Company/Module/view/adminhtml/templates/content.phtml
<p>內容放在這里</p>
添加檔案后,從命令列中運行以下命令。php bin/magento setup:upgrade
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/320570.html
標籤:
