0

We are using Magento 1.7.

enter image description here

In the admin panel I created a dropdown where I have "MYJ Resources" is there a way that when I click on this option I'm redirected to a blank phtml page I can customize with a form on it?

app/code/local/Sean/MasterCreate/etc/config.xml

<?xml version="1.0"?>
<!DOCTYPE config>

<config>
    <modules>
        <Sean_MasterCreate>
            <version>0.0.0</version>
        </Sean_MasterCreate>
    </modules>
    <global>
        <models>
            <mastercreate>
                <class>Sean_MasterCreate_Model</class>
            </mastercreate>
        </models>
        <blocks>
            <mastercreate>
                <class>Sean_MasterCreate_Block</class>
            </mastercreate>
        </blocks>
        <helpers>
            <mastercreate>
                <class>Sean_MasterCreate_Helper</class>
            </mastercreate>
        </helpers>
    </global>
    <adminhtml>
        <layout>
            <updates>
                <mastercreate>
                    <file>finance.xml</file>
                </mastercreate>
            </updates>
        </layout>
    </adminhtml>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <mastercreate before="Mage_Adminhtml">Sean_MasterCreate_Adminhtml</mastercreate>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
    <frontend>
        <routers>
            <mastercreate>
                <use>standard</use>
                <args>
                    <frontName>mastercreate</frontName>
                    <module>Sean_MasterCreate</module>
                </args>
            </mastercreate>
        </routers>
    </frontend>
</config>

app/code/local/Sean/MasterCreate/etc/adminhtml.xml

<?xml version="1.0"?>
<!DOCTYPE config>

<config>
    <menu>
        <mastercreate translate="title" module="mastercreate">
            <title>MYJ Tools</title>
            <sort_order>89</sort_order>
            <children>
                <usercreate module="mastercreate">
                    <title>Create Users</title>
                    <sort_order>0</sort_order>
                    <action>adminhtml/Creation/createCustomerForm</action>
                </usercreate>
                <productcreate>
                    <title>Create Products</title>
                    <sort_order>1</sort_order>
                    <action>adminhtml/Creation/createProductForm</action>
                </productcreate>
                <weightupdate>
                    <title>Update Weights</title>
                    <sort_order>2</sort_order>
                    <action>adminhtml/Creation/createWeightForm</action>
                </weightupdate>
                <companyinfo>
                    <title>MYJ Resources</title>
                    <sort_order>3</sort_order>
                    <action>adminhtml/Warehouse/createWarehouseForm</action>
                </companyinfo>
            </children>
        </mastercreate>
    </menu>
</config>

Here is my controller: app/code/local/Sean/MasterCreate/controllers/Adminhtml/WarehouseController.php

<?php

class Sean_MasterCreate_Adminhtml_WarehouseController extends Mage_Adminhtml_Controller_Action
{
    public function createWarehouseFormAction()
    {
        $this->loadLayout();
        $this->_addContent(
            $this->getLayout()->createBlock('mastercreate/adminhtml_warehouse_display')
        );
        $this->_initLayoutMessages('adminhtml/session'); //this will allow flash messages
        $this->renderLayout();
    }
}

I create a form using: app/code/local/Sean/MasterCreate/Block/Adminhtml/Warehouse/Display/Form.php

<?php

class Sean_MasterCreate_Block_Adminhtml_Warehouse_Display_Form extends Mage_Adminhtml_Block_Widget_Form
{
    protected function _prepareForm()
    {
        //Id must be edit_form even if it's a different form
        $form = new Varien_Data_Form(array(
            'id' => 'edit_form',
            'action' => $this->getUrl('*/warehouse/updateInventory'),
            'method' => 'post'
        ));


        $form->setUseContainer(true);
        $this->setForm($form);

        return parent::_prepareForm();
    }
}

Here I set display stuff on the page but I want to write as if I were just writing on display.phtml with html and css: app/code/local/Sean/MasterCreate/Block/Adminhtml/Warehouse/Display.php

<?php

class Sean_MasterCreate_Block_Adminhtml_Warehouse_Display extends Mage_Adminhtml_Block_Widget_form_Container
{
    public function __construct()
    {
        $this->_objectId = 'product_id';
        $this->_blockGroup = 'mastercreate';
        $this->_controller = 'adminhtml_warehouse';
        $this->_mode = 'display';

        $this->setTemplate('finance/action.phtml');

        parent::__construct();
    }

    public function getHeaderText()
    {
        return Mage::helper('mastercreate')->__('MYJ Finance / Inventory');
    }

    //This is automatically tied to where the form action goes/is
    public function getSaveUrl()
    {
        return $this->getUrl('*/warehouse/updateInventory');
    }
}

app/design/adminhtml/default/default/layout/finance.xml

<?xml version="1.0"?>
<layout version="0.1.0">
    <mastercreate_warehouse_createwarehouseform>
        <reference name="content">
            <block type="adminhtml/template" name="warehouse_display" template="finance/action.phtml" />
        </reference>
    </mastercreate_warehouse_createwarehouseform>
</layout>

app/design/adminhtml/default/default/template/finance/action.phtml

<h1> Testing Here </h1>

I got it working, I just had to clear the cache however how can I have the phtml file under the header?

enter image description here

  • In your layout file change ../template/finance/action.phtml to finance/action.phtml – Piyush Jul 11 '17 at 18:31
  • I changed it but still not working quite yet – CodingMageSheen Jul 11 '17 at 18:39
2

To add a custom phtml file to admin page

change your controller file action to

public function createWarehouseFormAction()
{
    $this->loadLayout();
    $this->renderLayout();
}

add in your module's layout.xml file

<?xml version="1.0"?>
<layout version="0.1.0">
    <yourmodule_controller_action>
        <reference name="content">
            <block type="adminhtml/template" name="block_name" template="path_to_your_template.phtml" />
        </reference>
    </yourmodule_controller_action>
</layout>
  • How does the module know where to find the layout.xml file? Do I have to follow a certain file path structure? – CodingMageSheen Jul 11 '17 at 17:40
  • I've edited my question with your changes but I think something is wrong still – CodingMageSheen Jul 11 '17 at 17:48

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.