1

I am trying to develop a custom module that must appear as a sub menu item in the admin->system menu.

I have been looking at a number of examples on Google and have been taking advice from this group and I think I am close to having my module working. The setup is running and the module is getting registered in the core_resource table and the table required to be created by this module is happening. At the moment the entry in admin->system is not getting created and after many hours of hunting and trying ideas suggested on various sites I am at a loss.

My module menu structure is as follows

app
   code
      local
         Steam
            Emarsys
               Block
               controllers
               etc
               Helper
               Model
               sql

In app/etc/modules I have Steam_Emarsys.xml and it contains

<?xml version="1.0"?>
<config>
<modules>
    <Steam_Emarsys>
        <active>true</active>
        <codePool>local</codePool>
    </Steam_Emarsys>
</modules>

</config>

I assume this is working as the module is registered

In Emarsys/etc I have config.xml

<?xml version="1.0"?>
<config>
<modules>
    <Steam_Emarsys>
        <version>0.0.1</version>
    </Steam_Emarsys>
</modules>
<global>

    <blocks>
        <steam_emarsys_adminhtml>
           <class>Steam_Emarsys_Block_Adminhtml</class>
        </steam_emarsys_adminhtml>
    </blocks>

    <helpers>
        <steam_emarsys>
            <class>Steam_Emarsys_Helper</class>
        </steam_emarsys>
    </helpers>

    <models>
        <steam_emarsys>
            <class>Steam_Emarsys_Model</class>
            <resourceModel>steam_emarsys_resource</resourceModel>
        </steam_emarsys>
        <steam_emarsys_resource>
            <class>Steam_Emarsys_Model_Resource</class>
            <entities>
                <brand>
                    <table>steam_emarsys_brand</table>
                </brand>
            </entities>
        </steam_emarsys_resource>
    </models>

    <resources>
        <steam_emarsys_setup>
            <setup>
                <module>Steam_Emarsys</module>
                <class>Mage_Core_Model_Resource_Setup</class>
            </setup>
            <connection>
                <use>core_setup</use>
            </connection>
        </steam_emarsys_setup>
    </resources>
</global>

<admin>
    <routers>
        <steam_emarsys_admin>
            <use>admin</use>
            <args>
               <module>Steam_Emarsys_Adminhtml</module>
                <frontName>brand-directory-admin</frontName>
            </args>
        </steam_emarsys_admin>
    </routers>
</admin>

</config>

I also have adminhtml.xml

<?xml version="1.0"?>
<config>
<menu>
    <system>
        <children>
            <brand translate="title" module="steam_emarsys">
                <title>Manage Emarsys</title>
                <sort_order>120</sort_order>
                <action>steam_emarsys_admin/brand</action>
            </brand>
        </children>
    </system>
</menu>

<acl>
    <resources>
        <admin>
            <system>
                <children>
                    <brand translate="title" module="steam_emarsys">
                        <title>Manage Emarsys</title>
                    </brand>
                </children>
            </system>
        </admin>
    </resources>
</acl>
</config>

In controllers->AdminHtml I have BrandController.php and in there I have the ACL (isAllowed) funtionality

<?php
class Steam_Emarsys_Adminhtml_BrandController
extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
    $brandBlock = $this->getLayout()
        ->createBlock('steam_emarsys_adminhtml/brand');

    $this->loadLayout()
        ->_addContent($brandBlock)
        ->renderLayout();
}

public function editAction()
{

    $brand = Mage::getModel('steam_emarsys/brand');
    if ($brandId = $this->getRequest()->getParam('id', false)) {
        $brand->load($brandId);

        if ($brand->getId() < 1) {
            $this->_getSession()->addError(
                $this->__('Emarsys data no longer exists.')
            );
            return $this->_redirect(
                'steam_emarsys_admin/brand/index'
            );
        }
    }

    if ($postData = $this->getRequest()->getPost('brandData')) {
        try {
            $brand->addData($postData);
            $brand->save();

            $this->_getSession()->addSuccess(
                $this->__('Emarsys data has been saved.')
            );

            return $this->_redirect(
                'steam_emarsys_admin/brand/edit',
                array('id' => $brand->getId())
            );
        } catch (Exception $e) {
            Mage::logException($e);
            $this->_getSession()->addError($e->getMessage());
        }

    }

    Mage::register('current_brand', $brand);

    $brandEditBlock = $this->getLayout()->createBlock(
        'steam_emarsys_adminhtml/brand_edit'
    );

    $this->loadLayout()
        ->_addContent($brandEditBlock)
        ->renderLayout();
}

public function deleteAction()
{
    $brand = Mage::getModel('steam_emarsys/brand');

    if ($brandId = $this->getRequest()->getParam('id', false)) {
        $brand->load($brandId);
    }

    if ($brand->getId() < 1) {
        $this->_getSession()->addError(
            $this->__('Emarsys data no longer exists.')
        );
        return $this->_redirect(
            'steam_emarsys_admin/brand/index'
        );
    }

    try {
        $brand->delete();

        $this->_getSession()->addSuccess(
            $this->__('Emarsys data has been deleted.')
        );
    } catch (Exception $e) {
        Mage::logException($e);
        $this->_getSession()->addError($e->getMessage());
    }

    return $this->_redirect(
        'steam_emarsys_admin/brand/index'
    );
}

protected function _isAllowed()
{
    $actionName = $this->getRequest()->getActionName();
    switch ($actionName) {
        case 'index':
        case 'edit':
        case 'delete':
        default:
            $adminSession = Mage::getSingleton('admin/session');
            $isAllowed = $adminSession
                ->isAllowed('steam_emarsys/brand');
            break;
    }

    return $isAllowed;
}
}

I am not seeing any log messages in exception.log, system.log or the apache logs

I am expecting to see the Manage Emarsys menu item at the bottom of the admin->system menu and the action for this menu item should be the Emarsys Block being rendered.

I would really appreciate any guidance or help as to what I am doing wrong. If anyone needs to see any other files I can post these

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.