Magento tutorial create a module for the backend (admin page)

Magento tutorial create a module for the backend (admin page)

October 10, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento tutorial create a module for the backend (admin page)

Creating a Multi-Page Magento Admin Module: A Comprehensive Guide

Are you looking to extend your Magento backend functionality by creating a custom admin module? I’ll walk you through the process of building an admin module with multiple pages - an overview page and a form to create items.

Understanding Magento Admin Modules

Magento relies on modules for its core and extension functionality. An admin module allows you to add or modify features specifically designed for store administrators. The structure is similar to a regular Magento module but requires specific configuration for the admin configuration.

Setting Up Your Development Environment

Before we dive into coding, ensure your development environment is ready:

  1. Have Magento installed and running on your local server.
  2. Set up an FTP client (like FileZilla) to upload files.
  3. Create a new folder named app/code/Vendor/YourModule in your Magento root directory.

Creating the Overview Page

Let’s start by creating the overview page for our admin module.

  1. Under Vendor/YourModule/etc/adminhtml, create a routes.xml file:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="admin">
        <route frontName="your_module" id="your_module" />
    </router>
</config>

Replace your_module with the name of your module.

  1. In Vendor/YourModule/Controller/Adminhtml/Index, create an Index.php file:
namespace Vendor\YourModule\Controller\Adminhtml\Index;

class Index extends \Magento\Backend\App\Action
{
    public function execute()
    {
        $this->_view->loadLayout();
        $this->_setActiveMenu('Vendor_YourModule::index');
        $this->getMessageManager()->addSuccess(__('Hello, This is custom Vendor YourModule'));
        $this->_addContent($this->_view->getLayout()->createBlock(
            'Magento\Framework\View\Element\Template'
        )->setTemplate('Vendor_YourModule::my_template.phtml'));
        return $this->_view->getResponse();
    }
}
  1. Create a my_template.phtml file under Vendor/YourModule/view/adminhtml/templates:
<div class="page-header">
    <h1><?php echo __('My Custom Page'); ?></h1>
</div>
  1. Update your module’s etc/module.xml:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Vendor_YourModule" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Backend"/>
        </sequence>
    </module>
</config>

Creating the Form to Create an Item

To create a form, follow these steps:

  1. In Vendor/YourModule/etc/adminhtml/menu.xml, add the following code:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Adminhtml:etc/menu.xsd">
    <menu>
        <add id="Vendor_YourModule::index"
             title="My Custom Module"
             module="Vendor_YourModule"
             sortOrder="50"
             resource="Vendor_YourModule::your_module" />
    </menu>
</config>
  1. In Vendor/YourModule/Controller/Adminhtml/Index/Save.php, create a save action:
namespace Vendor\YourModule\Controller\Adminhtml\Index;

class Save extends \Magento\Backend\App\Action implements \Magento\Backend\Model\Auth\AuthorizationInterface
{
    // Implementation here...
}
  1. Create the form in Vendor/YourModule/view/adminhtml/templates/save.phtml:
<form action="<?php echo $block->getSaveUrl(); ?>" method="post" id="your_module_form">
    <!-- Your form fields go here -->
</form>

Finalizing and Activating Your Extension

To complete the process:

  1. Flush Magento cache.
  2. Navigate to System > Configuration in the backend.
  3. Click on Advanced under Magento Company.
  4. In the Developer tab, set Enable Developer Mode to Yes.
  5. Set Debug and Template Path Hints to Yes.
  6. Log out and log back in.

You should now see your custom admin menu item in the Magento backend navigation.

Remember, building an admin module requires a thorough understanding of Magento’s architecture and OOP principles. For more detailed examples, check out the official Magento 2 documentation or explore Laravel Company’s guide on Magento development best practices.

Happy coding!

Extensions Admin Configuration CLI

Our network