Magento 2
Create an Admin Controller
Free Preview
etc/adminhtml/routes.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <!--
    Admin controllers are assigned to a route defined within the "admin" router.
    -->
    <router id="admin">
        <!--
        The frontName is the actual route you would like to return.
        The route id is usually the same value, but just needs to be unique.

        This is accessible at https://[yourdomain.com]/[admin_url]/myroute
        -->
        <route id="myroute" frontName="myroute">
            <!-- This is the module responsible for handling this route. -->
            <module name="Macademy_MyModule"/>
        </route>
    </router>
</config>
Controller/Adminhtml/Faq/Index.php
<?php declare(strict_types=1);

// Admin controllers are placed within the Controller/Adminhtml directory.
namespace Macademy\MyModule\Controller\Adminhtml\Widget;

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

// Be sure to extend the App\Action class of the Magento_Backend module...
class Index extends Action implements HttpGetActionInterface
{
    // ...which adds in extra capabilities, such as access controls.

    // The value assigned to this constant is an ACL resource.
    // This ACL resource is used to determine access to this controller.
    const ADMIN_RESOURCE = 'Macademy_MyModule::widget';

    /** @var PageFactory */
    protected $pageFactory;

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

    /**
     * @return Page
     */
    public function execute(): Page
    {
        return $this->pageFactory->create();
    }
}
Want to learn more?

Visit M.academy to learn much more about Magento, Laravel, PHP, Javascript, & Docker.

M.academy logo