Magento 控制器转发在管理员中



我正在根据这篇文章创建简单的Magento模块.
我的管理员"新建项目"操作有问题。

<?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');
}
项目

索引操作工作并显示我的项目,当我单击任何项目时,它会按预期返回"编辑"。不幸的是,单击"添加新项目"会给出 404(url 很好)。

有什么想法吗?

您需要添加 adminhtml 布局更新 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>

当然,它需要在配置中设置.xml

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

您可能需要在 editAction() 中加载/渲染布局

根据您调用请求的自定义操作的方式,您可能需要向配置中添加一些内容.xml

假设这就是你所说的:http(s)://yourdomain.com/index.php/gallery/admin_gallery/new

然后将以下内容添加到您的配置中.xml在 <admin><routers> 节点内

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

最新更新