<?xml version='1.0'?>
<config>
<modules>
<MageCheck_CreateAdminController>
<active>true</active>
<codePool>local</codePool>
</MageCheck_CreateAdminController>
</modules>
</config>
File path: app/etc/modules/MageCheck_CreateAdminController.xml
<?xml version='1.0'?>
<config xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='urn:magento:framework:App/etc/routes.xsd'>
<router id='admin'>
<route id='tutorial' frontName='tutorial'>
<module name='MageCheck_Tutorial' before='Magento_Backend' />
</route>
</router>
</config>
File path: app/code/MageCheck/Tutorial/etc/adminhtml/routes.xml
<?xml version='1.0'?>
<config>
<modules>
<MageCheck_CreateAdminController>
<version>1.0.0</version>
</MageCheck_CreateAdminController>
</modules>
<global>
<helpers>
<magecheck_createadmincontroller>
<class>Mage_Core_Helper</class>
</magecheck_createadmincontroller>
</helpers>
</global>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<foo_bar before='Mage_Adminhtml'>MageCheck_CreateAdminController_Adminhtml</foo_bar>
</modules>
</args>
</adminhtml>
</routers>
</admin>
</config>
File path: app/code/local/MageCheck/CreateAdminController/etc/config.xml
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'MageCheck_Tutorial',
__DIR__
);
File path: app/code/MageCheck/Tutorial/registration.php
<?php class MageCheck_CreateAdminController_Adminhtml_CustomController extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
$this->loadLayout()
->_setActiveMenu('mycustomtab')
->_title($this->__('Index Action'));
// ...
$this->renderLayout();
}
public function listAction()
{
$this->loadLayout()
->_setActiveMenu('mycustomtab')
->_title($this->__('List Action'));
// ...
$this->renderLayout();
}
}
File path: app/code/local/MageCheck/CreateAdminController/controllers/Adminhtml/CustomController.php
<?php
namespace MageCheck\Tutorial\Controller\Adminhtml\Index;
class Index extends \Magento\Backend\App\Action
{
protected $resultPageFactory;
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\Registry $coreRegistry,
\Magento\Framework\View\Result\PageFactory $resultPageFactory
) {
$this->resultPageFactory = $resultPageFactory;
parent::__construct($context, $coreRegistry);
}
public function execute()
{
echo 'My admin controller';
exit;
}
protected function _isAllowed()
{
return true;
}
}
File path: app/code/MageCheck/Tutorial/Controller/Adminhtml/Index/Index.php
<?xml version='1.0' encoding='UTF-8'?>
<config>
<menu>
<mycustomtab module='magecheck_createadmincontroller' translate='title'>
<title>MageCheck</title>
<sort_order>100</sort_order>
<children>
<index module='magecheck_createadmincontroller' translate='title'>
<title>Tutorial 1</title>
<sort_order>1</sort_order>
<action>adminhtml/custom</action>
</index>
<list module='magecheck_createadmincontroller' translate='title'>
<title>Tutorial 2</title>
<sort_order>2</sort_order>
<action>adminhtml/custom/list</action>
</list>
</children>
</mycustomtab>
</menu>
<acl>
<resources>
<admin>
<children>
<custom translate='title' module='magecheck_createadmincontroller'>
<title>My Controller</title>
<sort_order>-100</sort_order>
<children>
<index translate='title'>
<title>Index Action</title>
<sort_order>1</sort_order>
</index>
<list translate='title'>
<title>List Action</title>
<sort_order>2</sort_order>
</list>
</children>
</custom>
</children>
</admin>
</resources>
</acl>
</config>
File path: app/code/local/MageCheck/CreateAdminController/etc/adminhtml.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='MageCheck_Tutorial::helloworld' title='MageCheck' module='MageCheck_Tutorial' sortOrder='51' resource='MageCheck_Tutorial::helloworld'/>
<add id='MageCheck_Tutorial::post' title='Tutorials' module='MageCheck_Tutorial' sortOrder='10' action='magecheck_tutorial/post' resource='MageCheck_Tutorial::post' parent='MageCheck_Tutorial::helloworld'/>
<add id='MageCheck_Tutorial::hello_configuration' title='Configuration' module='MageCheck_Tutorial' sortOrder='99' parent='MageCheck_Tutorial::helloworld' action='adminhtml/system_config/edit/section/helloworld' resource='MageCheck_Tutorial::helloworld_configuration'/>
</menu>
</config>
File path: app/code/MageCheck/Tutorial/etc/adminhtml/menu.xml
This is the sample way to create a Backend Controller in Magento!
Have you decided on an online Business Plan website?