0

I created adminhtml controller under practice->test->controllers->adminhtml->indexController.php it's working fine. But I created one menu in back-end and it's showing when I click on menu i created action to redirect my custom afficher.phtml, it's not redirecting given 401 error.

can anyone tell me where I went wrong?

my code is

practice->test->controllers->adminhtml->indexController.php

<?php

class Practice_Test_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
{
    public function indexAction()
    {
        $this->loadLayout();
        $this->renderLayout();
        //echo 'admin test';
    }
}

practice->test->etc->config.xml

<admin>
        <routers>
            <test>
                <use>admin</use>
                <args>
                    <module>Practice_Test_Adminhtml</module>
                    <frontName>practiceadmin</frontName>
                </args>
            </test>
        </routers>
    </admin>
    <adminhtml>
        <layout>
            <updates>
                <test>
                    <file>test.xml</file>
                </test>
            </updates>
        </layout>
        <menu>
            <test translate="title" module="adminhtml">
                <title>My Plugin</title>
                <sort_order>100</sort_order>
                <children>
                    <set_time>
                        <title>Address Book</title>
                        <action>practiceadmin/adminhtml_index</action>
                    </set_time>
                </children>
            </test>
        </menu>
    </adminhtml>

adminhtml->default->Practice->layout->test.xml

<?xml version="1.0"?>
<layout version="0.1.0">
    <test_adminhtml_index_index>
        <reference name="content">
            <block name="template1" type="test/template" template="test/afficher.phtml"></block>
        </reference>
    </test_adminhtml_index_index>
</layout>

adminhtml->default->Practice->test->afficher.phtml

<input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>"  />

<Div>
    Admin Html
</Div>

thanks in advance.

1

In your indexAction() , you have not called any block and phtml file to show. Write you function like this

public function indexAction()
{
       $this->loadLayout();
       $this->_title($this->__("Operations"));
       $block = $this->getLayout()->createBlock('module/folder_blockName')->setTemplate("FolderName/File.phtml");
       $this->_setActiveMenu('menu/children'); // to set the menu item active
       $this->getLayout()->getBlock('content')->append($block);
       $this->renderLayout();

}
0

This part of the config:

<action>practiceadmin/adminhtml_index</action>

should actually be

<action>practiceadmin/index</action>

This is why the change is necessary. Consider when given the action of practiceadmin/adminhtml_index, the first half is translated into Practice_Test_Adminhtml and the second half is translated into Adminhtml_IndexController then the two parts are joined together. The resulting class name has Adminhtml in it twice.

  • hi clockworkgeek, my afficher.phtml file is not showing. it is showing empty page with menu items – Manoj Kumar Oct 9 '13 at 11:28
  • Your layout says template="test/afficher.phtml" but the created file is Practice/test/afficher.phtml. Change either one of those to match the other. – clockworkgeek Oct 9 '13 at 12:15

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.