Magento 1.9 – Creating First Custom Content Page in Admin

adminmagento-1.9

Total beginner with Magento… I've installed magento, and followed this article to the T. I have no issue with the article, it basically creates a custom admin menu item, and when you click on it you get a blank page.

I've gotten that far, but now I'd like to show something instead of the blank page. My end goal is to call some custom php code to show in the admin section when the custom admin menu item is clicked.

I'm a little lost on what the next steps are to achieve this goal. Do I need to setup templates / layouts for this, or is there a way to just route directly to my own custom php page? Are there any good tutorials for this? I've tried searching around but I'm not sure if I am using the right terminology etc.

I'm using the latest version of Magento. Thanks!

Best Answer

The starting point of displaying the content for your controller would be the following code from the Alan Storm's article

#File: app/code/community/Pulsestorm/Adminhello/controllers/AdminhelloController.php

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

As you can see the controller renders a Layout. So you have to create such a layout. In module's config.xml please define layout file

#File: app/code/community/Pulsestorm/Adminhello/etc/config.xml

<config>
    <adminhtml>
        <layout>
            <updates>
                <adminhello>
                    <file>adminhello.xml</file>
                </adminhello>
            </updates>
        </layout>
    </adminhtml>
</config>

Place adminhello.xml file to app/design/adminhtml/default/default/layout. It should contain the following code

#File: app/design/adminhtml/default/default/layout/adminhello.xml

<adminhtml_adminhello_index>
    <block type="core/template" output="toHtml" name="templateBlock" template="adminhello/hello.phtml">
</adminhtml_adminhello_index>

Create your template app/design/adminhtml/default/default/template/adminhello/hello.phtml and put any code there.

It is the simplest way to display the content of phtml template by requesting your controller. For more detailed instructions please refer to

http://alanstorm.com/layouts_blocks_and_templates
and Magento Extension Developer's Guide

Related Topic