1

I'm creating simple Magento module based on this article.
I have a problem with my admin New Item action.

<?php

class Namespace_Gallery_Adminhtml_GalleryController extends Mage_Adminhtml_Controller_Action
{
protected function _initAction()
{
    $this->loadLayout()
        ->_setActiveMenu('namespace/gallery');

    return $this;
}

public function indexAction()
{
    $this->_initAction();
    $this->_addContent($this->getLayout()->createBlock('gallery/adminhtml_gallery'));
    $this->renderLayout();
}

public function editAction()
{
    echo 'edit';
}

public function newAction()
{
    $this->_forward('edit');
}

Items indexAction works and displays my items, when I click on any item it returns 'edit' as intended. Unfortunately clicking "Add new item" gives 404 (url is good).

Any ideas?

Roman Snitko
  • 3,655
  • 24
  • 29
Dave
  • 463
  • 1
  • 3
  • 14
  • Wait, are you seeing "404" displayed in the content area of an admin page, or are you actually receiving a 404 response header? The former is an indication that ACL for that resource is borked. – benmarks Sep 18 '12 at 10:10
  • looks like the mystery located in your statement: `url is good`. How do you generate / create the url for newAction? – ivantedja Sep 19 '12 at 14:53

2 Answers2

0

You need to add adminhtml layout update xml:

<?xml version="1.0"?>
<layout>
    <[module]_adminhtml_[controller]_index>
        <reference name="content">
                <block type="[module]/adminhtml_[frontname]" name="[module]_grid"/>
        </reference>
    </[module]_adminhtml_[controller]_index>
</layout>

And of course it needs to be set in config.xml

<adminhtml>
    <layout>
        <updates>
            <[module]>
                <file>[module].xml</file>
            </[module]>
        </updates>
    </layout>
</adminhtml>

And you may need to load/render layout in editAction()

Nate
  • 578
  • 2
  • 8
  • editAction() and indexAction() works great. There is a problem with newAction() (as I mentioned). – Dave Sep 17 '12 at 15:46
0

Depending on how you call your requested custom action you may have to add something to your config.xml

Assuming that this is what you call: http(s)://yourdomain.com/index.php/gallery/admin_gallery/new

then add the following to your config.xml inside the <admin><routers>-node

<gallery>
    <use>admin</use>
    <args>
        <module>Namespace_Gallery</module>
        <frontName>gallery</gallery>
    </args>
</gallery>