Magento – Magento 1.9.3 admin custom page URL redirect to dashboard

admincustommagento-1.9page

I have creating a custom page in admin side. When i try to access that page automatically redirect to dashboard

my code is following:

app\code\local\EPayment\EPayment\controllers\Adminhtml\EpaymentbackendController.php

<?php
class EPayment_EPayment_Adminhtml_EpaymentbackendController extends Mage_Adminhtml_Controller_Action
{
    public function historyAction()
    {
        $this->loadLayout() ; 
        $this->renderLayout(); 
        //Zend_Debug::dump($this->getLayout()->getUpdate()->getHandles());die;
    }
}

app\design\adminhtml\default\default\layout\epayment.xml

<?xml version="1.0"?>
<layout version="0.1.0">

  <epayment_adminhtml_epaymentbackend_history>
    <reference name="content">
      <block type="epayment/adminhtml_epaymentbackend" name="epaymentbackend" template="epayment/history.phtml"/>
    </reference>
  </epayment_adminhtml_epaymentbackend_history>

</layout>

app\design\adminhtml\default\default\template\epayment\history.phtml

<div class="content-header">
    <table cellspacing="0">
        <tr>
            <td><h3 class="icon-head head-sales-order">Epayment History</h3></td>
        </tr>
    </table>
</div>

app\code\local\EPayment\EPayment\etc\config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <EPayment_EPayment>
      <version>0.1.0</version>
    </EPayment_EPayment>
  </modules>
  <frontend>
    <routers>
      <epayment>
        <use>standard</use>
          <args>
            <module>EPayment_EPayment</module>
            <frontName>epayment</frontName>
          </args>
      </epayment>
    </routers>
        <layout>
          <updates>
            <epayment>
              <file>epayment.xml</file>
            </epayment>
          </updates>
        </layout>
  </frontend>
  <global>
    <helpers>
      <epayment>
        <class>EPayment_EPayment_Helper</class>
      </epayment>
    </helpers>
    <blocks>
      <epayment>
        <class>EPayment_EPayment_Block</class>
      </epayment>
    </blocks>
  </global>
  <admin>
    <routers>
      <epayment>
        <use>admin</use>
        <args>
          <module>EPayment_EPayment</module>
          <frontName>admin_epayment</frontName>
        </args>
      </epayment>
    </routers>
  </admin>
  <adminhtml>
    <menu>
      <epayment module="epayment">
        <title>EPayment</title>
        <sort_order>100</sort_order>
        <children>
          <epaymentbackend module="epayment">
            <title>EPayment</title>
            <sort_order>0</sort_order>
            <action>admin_epayment/adminhtml_epaymentbackend</action>
          </epaymentbackend>
        </children>
      </epayment>
    </menu>
    <acl>
      <resources>
        <all>
          <title>Allow Everything</title>
        </all>
        <admin>
          <children>
            <epayment translate="title" module="epayment">
              <title>EPayment</title>
              <sort_order>1000</sort_order>
              <children>
          <epaymentbackend translate="title">
            <title>EPayment</title>
          </epaymentbackend>
              </children>
            </epayment>
          </children>
        </admin>
      </resources>
    </acl>
    <layout>
      <updates>
        <epayment>
          <file>epayment.xml</file>
        </epayment>
      </updates>
    </layout>
  </adminhtml>
</config> 

Page URL
http://127.0.0.1/mathu/magento/index.php/admin_epayment/adminhtml_epaymentbackend/history/key/574480610c547e2835f47af6ccb85888/

I know i did small mistake.

Please help me

Best Answer

As a best practice suggested by Magento, you should not create new router for Magento admin panel. Instead you should ask Magento to read your module's controller before reading the core controller. For this, you need to modify your config.xml slightly as mentioned below:

app/code/local/EPayment/EPayment/etc/config.xml

<config>
    .....
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <epayment before="Mage_Adminhtml">EPayment_EPayment_Adminhtml</epayment>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
    ......
</config>

The next thing is admin menus should be defined in adminhtml.xml. Even though this is not mandatory, it is a best practice suggested by Magento.

Since we have modified the controller definition in config.xml, your menu URL will become adminhtml/epaymentbackend/history. This needs to be updated in the menu definition as follows:

app/code/local/EPayment/EPayment/etc/adminhtml.xml

<?xml version="1.0" encoding="UTF-8"?>

<config>
    <menu>
        <epayment module="epayment">
            <title>EPayment</title>
            <sort_order>100</sort_order>
            <children>
                <epaymentbackend module="epayment">
                    <title>EPayment</title>
                    <sort_order>0</sort_order>
                    <action>adminhtml/epaymentbackend/history</action>
                </epaymentbackend>
            </children>
        </epayment>
    </menu>
    <acl>
        <resources>
            <admin>
                <children>
                    <epayment translate="title" module="epayment">
                        <title>EPayment</title>
                        <sort_order>1000</sort_order>
                        <children>
                            <epaymentbackend translate="title">
                                <title>EPayment</title>
                            </epaymentbackend>
                        </children>
                    </epayment>
                </children>
            </admin>
        </resources>
    </acl>
</config>

Based on the new menu URL, your layout file should be modified as below:

app\design\adminhtml\default\default\layout\epayment.xml

<?xml version="1.0"?>

<layout version="0.1.0">
    <adminhtml_epaymentbackend_history>
        <reference name="content">
            <block type="epayment/adminhtml_epaymentbackend" name="epaymentbackend" template="epayment/history.phtml"/>
        </reference>
    </adminhtml_epaymentbackend_history>
</layout>