I am trying to create an admin page for my extension. I managed to add a new button to the side menu just below the System icon by adding the following menu.xml under etc/adminhtml.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../Magento/Backend/etc/menu.xsd">
        <add id="Test_Admin::adminpage" title="Test" module="Test_Admin" sortOrder="300" action="test/index" resource="Test_Admin::adminpage"/>

But I can't figure out how to route this button to a new page, this page should contain a form among other html.

In addition what is the way to create db-configs for my extension for the user to edit.


So firstly you can add a link to your menu and specify the module and action. For example your module could have the following xml. app/code/Stack/Example/etc/adminhtml/menu.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        <add id="Stack_Example::your_content" title="Your Content" module="Stack_Example" sortOrder="50"
             parent="Magento_Backend::content" resource="Stack_Example::your_content"/>
        <add id="Stack_Example::content" title="Content" module="Stack_Example" sortOrder="0"
             parent="Stack_Example::your_content" action="stack_example/content/info" resource="Stack_Example::content"/>

Now the action is split as follows:


So in our case we need the router stack_example defined in the adminhtml/routes.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    <router id="admin">
        <route id="stack_example" frontName="stack_example">
            <module name="Stack_Example" before="Magento_Backend"/>

Then the controller will be under Stack/Example/Controller/Adminhtml/Content/Info.php and should look as follows.

namespace Stack\Example\Controller\Adminhtml\Content;

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

class Info extends \Magento\Backend\App\Action
    const ADMIN_RESOURCE = 'Stack_Example::content';

     * @var PageFactory
    protected $resultPageFactory;

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

     * Update the breadcrumb and extra information
     * @return \Magento\Backend\Model\View\Result\Page
    public function execute()
        /** @var \Magento\Backend\Model\View\Result\Page $resultPage */
        $resultPage = $this->resultPageFactory->create();
        $resultPage->addBreadcrumb(__('Stack Example'), __('Content'));

        return $resultPage;

Action Attribute responsible for routing to the page.

More about routing see official documentation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.