Skip to content

Commit

Permalink
feat: Adding a Menu Item in the Admin
Browse files Browse the repository at this point in the history
  • Loading branch information
HDTran committed Apr 9, 2019
1 parent 204d258 commit 77fe60a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* app/code/local/MasteringMagento/Example/controllers/Adminhtml/ExampleController.php
*
* This example code is provided for use with the Mastering Magento video
* series, by Packt Publishing.
*
* @author Franklin P. Strube <franklin.strube@gmail.com>
* @category MasteringMagento
* @package Example
* @copyright Copyright (c) 2012 Packt Publishing (http://packtpub.com)
*/
class MasteringMagento_Example_Adminhtml_ExampleController extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
$this->loadLayout();

return $this->renderLayout();
}
}

?>
24 changes: 24 additions & 0 deletions app/code/local/MasteringMagento/Example/etc/adminhtml.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<!DOCTYPE config>
<!--
/**
* app/code/local/MasteringMagento/Example/etc/adminhtml.xml
*
* This example code is provided for use with the Mastering Magento video
* series, by Packt Publishing.
*
* @author Franklin P. Strube <franklin.strube@gmail.com>
* @category MasteringMagento
* @package Example
* @copyright Copyright (c) 2012 Packt Publishing (http://packtpub.com)
*/
-->
<config>
<menu>
<example translate="title" module="example">
<title>Example</title>
<sort_order>1000</sort_order>
<action>adminhtml/example</action>
</example>
</menu>
</config>
13 changes: 13 additions & 0 deletions app/code/local/MasteringMagento/Example/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@
</helpers>
</global>

<!-- admin -->
<admin>
<routers>
<adminhtml>
<args>
<modules>
<example before="Mage_Adminhtml">MasteringMagento_Example_Adminhtml</exmaple>>
</modules>
</args>
</adminhtml>
</routers>
</admin>

<!-- anything beginning with frontName example will get routed here -->
<frontend>
<routers>
Expand Down

1 comment on commit 77fe60a

@HDTran
Copy link
Owner Author

@HDTran HDTran commented on 77fe60a Apr 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3.10 Recap: Adding a Menu Item in the Admin

Menu Configuration

Add your menu configuration to app/code/local/MasteringMagento/Example/etc/adminhtml.xml.

<config>
    <menu>
        <example translate="title" module="example">
            <title>Example</title>
            <sort_order>1000</sort_order>
            <action>adminhtml/example</action>
        </example>
    </menu>
</config>

Admin Controller

In your module configuraiton, tap into the existing admin frontname:

<admin>
    <routers>
        <adminhtml>
            <args>
                <modules>
                    <example before="Mage_Adminhtml">MasteringMagento_Example_Adminhtml</example>
                </modules>
            </args>
        </adminhtml>
    </routers>
</admin>

Create an admin controller in app/code/local/MasteringMagento/Example/controllers/Adminhtml/ExampleController.php. Admin controllers must extend Mage_Adminhtml_Controller_Action.

class MasteringMagento_Example_Adminhtml_ExampleController extends Mage_Adminhtml_Controller_Action
{
    public function indexAction()
    {
        $this->loadLayout();
         return $this->renderLayout();
    }
}

Please sign in to comment.