Admin Url Format AdmintURL/{frontName}/{ControllerFolderInSmalllaetter}/{ActionFileNameINSameLetter}/...
app/code/{Vendor}/{ModuleName}/etc/adminhtml/routes.xml
(Define route id and frontName)app/code/{Vendor}/{ModuleName}/etc/acl.xml
(For ACL)app/code/{Vendor}/{ModuleName}/Controller/Adminhtml/{ControllerFolderName}/{ActionFileName}.php
(For URL)
--Some Source--
- https://devdocs.magento.com/guides/v2.3/extension-dev-guide/routing.html
- https://devdocs.magento.com/guides/v2.3/ext-best-practices/extension-coding/example-module-adminpage.html
- https://www.mageplaza.com/magento-2-module-development/magento-2-acl-access-control-lists.html
Under etc/adminhtml create the file routes.xml. The contents of this XML file tells Magento to route requests that use the frontName exampleadminnewpage to this module
Location should be: app/code/{Vendor}/{ModuleName}/etc/adminhtml
Format
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="admin">
<route id="{RouteId}" frontName="{frontName}">
<module name="{Vendor}_{ModuleName}"/>
</route>
</router>
</config>
Location should be: app/code/{Vendor}/{ModuleName}/etc/
Format
<?xml version="1.0" encoding="UTF-8"?>
<!-- Create Acl for Admin Permission -->
<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"> <!-- Indicated you at admin section -->
<resource id="{{Vendor}_{ModuleName}}::{UserDefineId1}" title="{UserDefineIdLabel1}" sortOrder="{sortOrder}">
<!-- Create an ACL resource id for Edit Example Url for this module -->
<resource id="{Vendor}_{ModuleName}::{UserDefineId2}" title="{UserDefineIdLabel2}" sortOrder="{sortOrder"/>
<!-- Create an ACL resource id for Delete Action Url for this module -->
<resource id="{Vendor}_{ModuleName}::{UserDefineId3}" title="{UserDefineIdLabel3}" sortOrder="{sortOrder"/>
</resource>
</resource>
</resources>
</acl>
</config>
Example
<?xml version="1.0" encoding="UTF-8"?>
<!-- Create Acl for Admin Permission -->
<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"> <!-- Indicated you at admin section -->
<resource id="StackExchange_Example::example_listing" title="Manage Example" sortOrder="500">
<!-- Create an ACL resource id for Edit Example Url for this module -->
<resource id="StackExchange_Example::example_edit" title="Edit Example" sortOrder="10"/>
<!-- Create an ACL resource id for Delete Action Url for this module -->
<resource id="StackExchange_Example::example_delete" title="Delete Example" sortOrder="20"/>
</resource>
</resource>
</resources>
</acl>
</config>
Location should be: app/code/{Vendor}/{ModuleName}/Controller/Adminhtml/{ControllerFolderName}/
Format
<?php
namespace {Vendor}\{ModuleName\Controller\Adminhtml\{ControllerFolderName};
use Magento\Backend\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;
class {ActionFileName} extends \Magento\Backend\App\Action
{
/**
* @url adminUrl/frontName/ControllerFolder/ActionfileName
* @example adminUrl/exampleadmin/example/listing
*/
/**
* @var \Magento\Framework\View\Result\PageFactory
*/
private $resultPageFactory;
public function __construct(
Context $context,
PageFactory $resultPageFactory
) {
parent::__construct($context);
$this->resultPageFactory = $resultPageFactory;
}
public function execute()
{
return $this->resultPageFactory->create();
}
}
Example:
<?php
namespace StackExchange\Example\Controller\Adminhtml\Example;
use Magento\Backend\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;
class Listing extends \Magento\Backend\App\Action
{
/**
* @url adminUrl/frontName/ControllerFolder/ActionfileName
* @example adminUrl/exampleadmin/example/listing
*/
/**
* @var \Magento\Framework\View\Result\PageFactory
*/
private $resultPageFactory;
public function __construct(
Context $context,
PageFactory $resultPageFactory
) {
parent::__construct($context);
$this->resultPageFactory = $resultPageFactory;
}
public function execute()
{
return $this->resultPageFactory->create();
}
}
Structure
{Vendor}
-- {ModuleName}
|
|-- Controller
| |-- Adminhtml
| |-- {ControllerFolderName}
| -- {ActionFileName}.php
|-- etc
| |-- adminhtml
| | -- routes.xml
| -- module.xml
| -- acl.xml
|-- composer.json
-- registration.php