1

I have a grid I built in the admin panel which displays a custom entity called 'tile'. What I'm trying to get working is the 'add new' button. I've created a form container, a form, added a tab to the left side, and a form element in the content section. However when I hit the 'add new' button, I get a white page with just the magento header and footer, and none of my blocks.

I've followed a couple tutorials, and at this point I'm relatively certain there's just a small bug or type preventing this all from working. Help appreciated. Relevant codes attached:

Here's my layout file:

<adminhtml_mymodule_tile_new>
    <reference name="content">
     <block type="mymodule/adminhtml_tile_new" name="tile_new" />
    </reference>
        <update handle="editor"/>
        <reference name="left">
            <block type="mymodule/adminhtml_tile_new_tabs" name="tile_new_tabs">
                <block type="mymodule/adminhtml_tile_new_tab_properties" name="tile_new_tab_properties"/>
                <action method="addTab"><name>properties_section</name><block>tile_new_tab_properties</block></action>
            </block>
        </reference>
        <reference name="content">
            <block type="mymodule/adminhtml_tile_new" name="tile_new"/>
        </reference>
</adminhtml_mymodule_tile_new>

Config file:

<config>
    <modules>
        <Company_MyModule>
            <version>1.1.0</version>
        </Company_MyModule>
    </modules>
    <global>
        <blocks>
            <mymodule>
                <class>Company_MyModule_Block</class>
            </mymodule>
        </blocks>
        <helpers>
            <mymodule>
                <class>Company_MyModule_Helper</class>
            </mymodule>
        </helpers>
        <models>

            <mymodule>
                <class>Company_MyModule_Model</class>
                <resourceModel>mymodule_resource</resourceModel>
            </mymodule>
            <mymodule_resource>
                <class>Company_MyModule_Model_Resource</class>
                <entities>
                    <product_project_link>
                        <tilele>mymodule_product_project_link</tilele>
                    </product_project_link>
                    <tile>
                        <tilele>mymodule_tile_grid_link</tilele>
                    </tile>
                </entities>
            </mymodule_resource>


        </models>
        <resources>
            <mymodule_setup>
                <setup>
                    <module>Company_MyModule</module>
                    <class>Company_MyModule_Model_Resource_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </mymodule_setup>
            <mymodule_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </mymodule_write>
            <mymodule_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </mymodule_read>


        </resources>

    </global>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <mymodule before="Mage_Adminhtml">Company_MyModule_Adminhtml</mymodule>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
    <adminhtml>
        <menu>
            <mymodule module="mymodule">
                <title>Tiles</title>
                <sort_order>100</sort_order>
                <action>adminhtml/tile/index</action>
            </mymodule>
        </menu>
        <acl>
            <resources>
                <all>
                    <title>Allow Everything</title>
                </all>
                <admin>
                    <children>
                        <mymodule translate="title" module="mymodule">
                            <title>MyModule</title>
                            <sort_order>1000</sort_order>
                            <children>
                                <mymodulebackend translate="title" module="mymodule">
                                    <title>Tiles</title>
                                </mymodulebackend>
                            </children>
                        </mymodule>
                    </children>
                </admin>
            </resources>
        </acl>
        <layout>
            <updates>
                <mymodule module="Company_MyModule">
                    <file>company/mymodule.xml</file>
                </mymodule>
            </updates>
        </layout>
    </adminhtml>
    <frontend>
        <layout>
            <updates>
                <mymodule module="Company_MyModule">
                    <file>company/mymodule.xml</file>
                </mymodule>
            </updates>
        </layout>
    </frontend>
</config>

app/code/local/Company/MyModule/controllers/Adminhtml/TileController.php:

<?php
class Company_MyModule_Adminhtml_TileController extends Mage_Adminhtml_Controller_Action
{

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

    }

    // Tells the grid to reload itself when we filter or use pagination
    public function gridAction()
    {

        $this->getResponse()->setBody($this->getLayout()->createBlock('mymodule/adminhtml_tile_grid')->toHtml());

    }


    /**
     * Served as both the edit action, and the new action
     */
    public function newAction()
    {

        $this->_title($this->__('New Tile Item'));

        $model = Mage::getModel('mymodule/tile');

        $data = Mage::getSingleton('adminhtml/session')->getFormData(true);
        if (!empty($data)) {
            $model->addData($data);
        }

        $this->loadLayout()->renderLayout();

    }


    /**
     * Load Banner from request
     *
     * @param string $idFieldName
     * @return Enterprise_Banner_Model_Banner $model
     */
    protected function _initTile($idFieldName = 'tile_id')
    {
        $this->_title($this->__('CMS'))->_title($this->__('Tile'));

        $id = (int)$this->getRequest()->getParam($idFieldName);
        $model = Mage::getModel('mymodule/tile');
        if ($id) {
            $model->load($id);
        }
        if (!Mage::registry('current_tile')) {
            Mage::register('current_tile', $model);
        }
        return $model;
    }


}

app/code/local/Company/MyModule/Block/Adminhtml/Tile/New.php:

<?php
class Company_MyModule_Block_Adminhtml_Tile_New extends Mage_Adminhtml_Block_Widget_Form_Container
{
    public function __construct() {

        $this->_objectId = 'id';
        $this->_controller = 'adminhtml_tile';
        $this->_blockGroup = 'mymodule';

        parent::__construct();

        $this->_updateButton('save', 'label', Mage::helper('mymodule')->__('Save'));
        $this->_updateButton('delete', 'label', Mage::helper('mymodule')->__('Delete'));

        $this->_addButton('save_and_edit_button', array(
            'label'   => Mage::helper('mymodule')->__('Save and Continue Edit'),
            'onclick' => 'saveAndContinueEdit()',
            'class'   => 'save'
        ), 100
        );
        $this->_formScripts[] = 'function saveAndContinueEdit() {
            editForm.submit($(\'edit_form\').action + \'back/edit/\');}';

    }

    /**
     * Get form action URL
     *
     */
    public function getFormActionUrl()
    {
        return $this->getUrl('*/*/save');
    }

    public function getHeaderText() {

        return Mage::helper('mymodule')->__('Add Tile Item');

    }


    /**
     * Get current loaded Tile ID
     *
     */
    public function getTileId()
    {
        return Mage::registry('tile_data')->getId();
    }


}

app/code/local/Company/MyModule/Block/Adminhtml/Tile/New/Form.php:

<?php
class Company_MyModule_Block_Adminhtml_Tile_New_Form extends Mage_Adminhtml_Block_Widget_Form
{
    protected function _prepareForm() {
        $form = new Varien_Data_Form(array(
            'id'        => 'new_form',
            'action'    => $this->getUrl('*/*/save', array(
                'id'    => $this->getRequest()->getParam('id'),
            )),
            'method'    => 'post',
            'enctype'   => 'multipart/form-data'
        ));
        $form->setUseContainer(true);
        $this->setForm($form);
        return parent::_prepareForm();
    }
}

app/code/local/Company/MyModule/Block/Adminhtml/Tile/New/Tabs.php:

<?php
class Company_MyModule_Block_Adminhtml_Tile_New_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
{
    public function __construct(){
        parent::__construct();
        $this->setId('tile_tabs');
        $this->setDestElementId('edit_form');
        $this->setTitle(Mage::helper('mymodule')->__('Item Information')); // Title of left column, where tabs appear, after edit
    }

    protected function _beforeToHtml(){
        $this->addTab('form_section', array(
            'label'  => Mage::helper('mymodule')->__('Item Information'),
            'title'  => Mage::helper('mymodule')->__('Item Information'),
            'content'    => $this->getLayout()->createBlock('mymodule/adminhtml_tile_new_tab_properties')->toHtml(),
        ));
        return parent::_beforeToHtml();
    }
}

app/code/local/Company/MyModule/Block/Adminhtml/Tile/New/Tab/Properties.php:

<?php
class Company_MyModule_Block_Adminhtml_Tile_New_Tab_Properties extends Mage_Adminhtml_Block_Widget_Form
    implements Mage_Adminhtml_Block_Widget_Tab_Interface
{

    protected function _prepareForm()
    {

        $form = new Varien_Data_Form();
        $htmlIdPrefix = 'tile_properties_';
        $form->setHtmlIdPrefix($htmlIdPrefix);


        $fieldset = $form->addFieldset('base_fieldset',
            array('legend'=>Mage::helper('mymodule')->__('Tile Properties'))
        );

        $fieldset->addField('type', 'select', array(
            'label'     => Mage::helper('mymodule')->__('Type'),
            'name'      => 'type',
            'required'  => true,
            'options'   => array(
                Enterprise_Banner_Model_Banner::STATUS_ENABLED  => Mage::helper('mymodule')->__('Project'),
                Enterprise_Banner_Model_Banner::STATUS_DISABLED => Mage::helper('mymodule')->__('Product'),
            ),
        ));

        $afterFormBlock = $this->getLayout()->createBlock('adminhtml/widget_form_element_dependence')
            ->addFieldMap("{$htmlIdPrefix}is_types", 'is_types')
            ->addFieldMap("{$htmlIdPrefix}types", 'types')
            ->addFieldDependence('types', 'is_types', '1');


        $this->setChild('form_after', $afterFormBlock);

        $this->setForm($form);

        return $this;
    }

    /**
     * Prepare label for tab
     *
     * @return string
     */
    public function getTabLabel()
    {
        return Mage::helper('mymodule')->__('Banner Properties');
    }

    /**
     * Prepare title for tab
     *
     * @return string
     */
    public function getTabTitle()
    {
        return $this->getTabLabel();
    }

    /**
     * Returns status flag about this tab can be showen or not
     *
     * @return true
     */
    public function canShowTab()
    {
        return true;
    }

    /**
     * Returns status flag about this tab hidden or not
     *
     * @return true
     */
    public function isHidden()
    {
        return false;
    }


}
  • Try to enable developer mode and make some intentional error in layout file to see if it's being loaded at all. Also, please include your config.xml as well. You also have defined reference to content section twice in layout, not sure if it would cause a problem but just to be on safe side! – Prateek Jul 2 '15 at 19:06
  • I have developer mode enabled. Have tried messing up the layout and haven't seen an error, but the layout is definitely used to get the grid on the previous page working, so I know some of the file is being read correctly, at least. The first reference to content is my adding the grid container to the page. The second reference I'm trying to add a form container to the 'new' page that you hit after clicking 'new' on the grid. Should I still refer to this as content, or something else? Will add my config file to the post in one minute. – carbide20 Jul 2 '15 at 19:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.