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

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

2 Answers 2

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 !!!

answered Aug 30, 2017 at 12:03
9
  • No bro still empty imgur.com/siLek3v Commented Aug 30, 2017 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 Commented Aug 30, 2017 at 12:40
  • Yes bro i did... :( Commented Aug 30, 2017 at 12:42
  • See this imgur.com/a/4d2Be Commented Aug 30, 2017 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 Commented Aug 30, 2017 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.

answered Aug 30, 2017 at 11:28
3
  • In template folder am creating a custom/declaration.phtml is this correct ? Commented Aug 30, 2017 at 11:49
  • it seems correct. Commented Aug 30, 2017 at 12:09
  • But sorry it's not working bro Commented Aug 30, 2017 at 12:30

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.