3

I have creating a new page in admin called declaration i refer this link Link Here

This my code app\etc\modules\JR_CreateAdminController.xml

<?xml version="1.0"?>
<config>
    <modules>
        <JR_CreateAdminController>
            <active>true</active>
            <codePool>community</codePool>
        </JR_CreateAdminController>
    </modules>
</config>

app\code\community\JR\CreateAdminController\controllers\Adminhtml\CustomController.php

<?php
class JR_CreateAdminController_Adminhtml_CustomController extends Mage_Adminhtml_Controller_Action
{
    public function declarationAction()
    {
        $this->loadLayout()
            ->_setActiveMenu('sales')
            ->_title($this->__('Declaration'));
        // my stuff

        $this->renderLayout();
    }
}

app\code\community\JR\CreateAdminController\etc\adminhtml.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <menu>
        <mycustomtab module="jr_createadmincontroller" translate="title">
            <title>My Custom Tab</title>
            <sort_order>100</sort_order>
            <children>
                <declaration module="jr_createadmincontroller" translate="title">
                    <title>Declaration Action</title>
                    <sort_order>3</sort_order>
                    <action>adminhtml/custom/declaration</action>
                </declaration>
            </children>
        </mycustomtab>
    </menu>
    <acl>
        <resources>
            <admin>
                <children>
                    <custom translate="title" module="jr_createadmincontroller">
                        <title>My Controller</title>
                        <sort_order>-100</sort_order>
                        <children>
                            <declaration translate="title">
                                <title>Declaration Action</title>
                                <sort_order>3</sort_order>
                            </declaration>
                        </children>
                    </custom>
                </children>
            </admin>
        </resources>
    </acl>
</config>

app\code\community\JR\CreateAdminController\etc\config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <JR_CreateAdminController>
            <version>1.0.0</version>
        </JR_CreateAdminController>
    </modules>
    <global>
        <helpers>
            <jr_createadmincontroller>
                <!-- Helper definition needed by Magento -->
                <class>Mage_Core_Helper</class>
            </jr_createadmincontroller>
        </helpers>
        <blocks>
            <jr_createadmincontroller>
                <class>JR_CreateAdminController_Block</class>
            </jr_createadmincontroller>
        </blocks>
    </global>

    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <foo_bar before="Mage_Adminhtml">JR_CreateAdminController_Adminhtml</foo_bar>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
    <adminhtml>
            <layout>
                <updates>
                    <jr_createadmincontroller>
                        <file>jr_createadmincontroller.xml</file>
                    </jr_createadmincontroller>
                </updates>
            </layout>
    </adminhtml>
</config>

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

<?xml version="1.0"?>
<layout>
    <adminhtml_createadmincontroller_custom_declaration>
        <reference name="content">
            <block type="jr_createadmincontroller/adminhtml_custom" name="custom_declaration" template="custom/declaration.phtml" />
        </reference>
    </adminhtml_createadmincontroller_custom_declaration>
</layout>

app\design\adminhtml\default\default\template\custom\declaration.phtml

<?php
echo 'Hi';

But still page showing empty

enter image description here

  • 1
    have you defined your block jr_createadmincontroller/adminhtml_custom? – Priyank Aug 30 '17 at 10:16
  • No i did not how can define that? – Ramesh S Aug 30 '17 at 10:16
  • try this code <block type="core/template" name="custom_declaration" template="custom/declaration.phtml" /> – Priyank Aug 30 '17 at 10:33
  • I put the code and delete all cache then run, sorry bro still empty – Ramesh S Aug 30 '17 at 10:39
2

I found several errors in your code you can check the below code and let me know if its working

app\code\community\JR\CreateAdminController\controllers\Adminhtml\CustomController.php

<?php
class JR_CreateAdminController_Adminhtml_CustomController extends Mage_Adminhtml_Controller_Action
{
    public function declarationAction()
    {
        $this->loadLayout()
            ->_setActiveMenu('sales')
            ->_title($this->__('Declaration'));
        $this->renderLayout();
    }
}

app\code\community\JR\CreateAdminController\etc\adminhtml.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <menu>
        <mycustomtab module="jr_createadmincontroller" translate="title">
            <title>My Custom Tab</title>
            <sort_order>100</sort_order>
            <children>
                <declaration module="jr_createadmincontroller" translate="title">
                    <title>Declaration Action</title>
                    <sort_order>3</sort_order>
                    <action>adminhtml/custom/declaration</action>
                </declaration>
            </children>
        </mycustomtab>
    </menu>
    <acl>
        <resources>
            <admin>
                <children>
                    <custom translate="title" module="jr_createadmincontroller">
                        <title>My Controller</title>
                        <sort_order>-100</sort_order>
                        <children>
                            <declaration translate="title">
                                <title>Declaration Action</title>
                                <sort_order>3</sort_order>
                            </declaration>
                        </children>
                    </custom>
                </children>
            </admin>
        </resources>
    </acl>
</config>

app\code\community\JR\CreateAdminController\etc\config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <JR_CreateAdminController>
            <version>1.0.0</version>
        </JR_CreateAdminController>
    </modules>
    <global>
        <helpers>
            <jr_createadmincontroller>
                <class>JR_CreateAdminController_Helper</class>
            </jr_createadmincontroller>
        </helpers>
        <blocks>
            <jr_createadmincontroller>
                <class>JR_CreateAdminController_Block</class>
            </jr_createadmincontroller>
        </blocks>
    </global>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <JR_CreateAdminController before="Mage_Adminhtml">JR_CreateAdminController_Adminhtml</JR_CreateAdminController>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
    <adminhtml>
        <layout>
            <updates>
                <jr_createadmincontroller>
                    <file>jr_createadmincontroller.xml</file>
                </jr_createadmincontroller>
            </updates>
        </layout>
    </adminhtml>
</config>

Correct the file name of your xml here

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

<?xml version="1.0"?>
<layout>
    <adminhtml_custom_declaration>
        <reference name="content">
            <block type="core/template" name="custom_declaration" template="custom/declaration.phtml" />
        </reference>
    </adminhtml_custom_declaration>
</layout>

Create two additional files

app\code\community\JR\CreateAdminController\Block\Adminhtml\Custom.php

<?php
class JR_CreateAdminController_Block_Adminhtml_Custom extends Mage_Adminhtml_Block_Template
{

}

app\code\community\JR\CreateAdminController\Helper\Data.php

<?php

class JR_CreateAdminController_Helper_Data extends Mage_Core_Helper_Abstract
{
}

Hopes this helps you out !!!

  • No bro still empty imgur.com/siLek3v – Ramesh S Aug 30 '17 at 12:38
  • Did you correct your xml file name defined in admin layout app\design\adminhtml\default\default\layout\jr_createadmincontroller.xml ? rename this file jr_customcontroller.xml to jr_createadmincontroller.xml – Priyank Aug 30 '17 at 12:40
  • Yes bro i did... :( – Ramesh S Aug 30 '17 at 12:42
  • See this imgur.com/a/4d2Be – Ramesh S Aug 30 '17 at 12:43
  • is your block file being called? Try creating a constructor and print something and test if your blocks get called? Can you update your code in your question to look out what else is missing? This worked for me – Priyank Aug 30 '17 at 12:46
2

Your layout file content should be

<?xml version="1.0"?>
<layout>
    <adminhtml_adminhtml_custom_declaration>
        <reference name="content">
            <block type="jr_createadmincontroller/adminhtml_custom" name="custom_declaration" template="custom/declaration.phtml" />
        </reference>
    </adminhtml_adminhtml_custom_declaration>
</layout>

There is also a custom block needs to be defined along with the above change. It should be like

File : app\code\community\JR\CreateAdminController\Block\Adminhtml\Custom.php

<?php
class JR_CreateAdminController_Block_Adminhtml_Custom extends Mage_Adminhtml_Block_Template
{
}

After these changes are done in your module, then clear your cache and try to load your page again.

  • In template folder am creating a custom/declaration.phtml is this correct ? – Ramesh S Aug 30 '17 at 11:49
  • it seems correct. – Rajeev K Tomy Aug 30 '17 at 12:09
  • But sorry it's not working bro – Ramesh S Aug 30 '17 at 12:30

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.