Magento Module Admin返回404

时间:2014-08-18 20:39:50

标签: magento module http-status-code-404 admin config

相信我,我知道在这个主题上有一百万个问题和答案。我有一个自定义模块,后端部分返回404.我已经搜索了配置文件,但它“似乎”没有任何错误(显然有一个,如果它返回404)。我想知道是否有任何一个有良好眼睛的人可以找到错误!如果有的话。模块正在加载(前端显示)。这是配置文件:

<?xml version="1.0"?>
<config>
    <modules>
        <Namespace_TestMySql4>
            <version>0.1.0</version>
        </Namespace_TestMySql4>
    </modules>
    <frontend>
        <routers>
            <testmysql4>
                <use>standard</use>
                <args>
                    <module>Namespace_TestMySql4</module>
                    <frontName>testmysql4</frontName>
                </args>
            </testmysql4>
        </routers>
        <layout>
            <updates>
                <testmysql4>
                    <file>testmysql4.xml</file>
                </testmysql4>
            </updates>
        </layout>
    </frontend>
    <!--admin add needed? -->
    <admin>
        <routers>
            <!--<testmysql4>
                <use>admin</use>
                <args>
                    <module>Namespace_TestMySql4</module>
                    <frontName>testmysql4</frontName>
                </args>
            </testmysql4> -->
            <adminhtml>
                <args>
                    <modules>
                        <testmysql4 before="Mage_Adminhtml">Namespace_TestMySql4_Adminhtml</testmysql4>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
    <adminhtml>
        <menu>
            <testmysql4 translate ="title" module="testmysql4">
                <title>TestMySql4</title>
                <sort_order>71</sort_order>
                <children>
                    <items translate="title" module="testmysql4">
                        <title>Manage Reports</title>
                        <sort_order>0</sort_order>
                        <action>adminhtml/testmysql4</action>
                    </items>
                </children>
            </testmysql4>
        </menu>
        <acl>
            <resources>
                <all>
                    <title>Allow Everything</title>
                </all>
                <admin>
                    <children>
                        <testmysql4>
                            <title>TestMySql4 Module</title>
                            <sort_order>200</sort_order>
                        </testmysql4>
                    </children>
                </admin>
            </resources>
        </acl>
        <layout>
            <updates>
                <testmysql4>
                    <file>testmysql4.xml</file>
                </testmysql4>
            </updates>
        </layout>
    </adminhtml>
    <!-- admin changes -->
    <global>
        <models>
            <testmysql4>
                <class>Namespace_TestMySql4_Model</class>
                <resouceModel>testmysql4_mysql4</resouceModel>
            </testmysql4>
            <testmysql4_mysql4>
                <class>Namespace_TestMySql4_Model_Mysql4</class>
                <entities>
                    <testmysql4>
                        <table>testmysql4</table>
                    </testmysql4>
                </entities>
            </testmysql4_mysql4>
        </models>
        <resources>
            <testmysql4_setup>
                <setup>
                    <module>Namespace_TestMySql4</module>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </testmysql4_setup>
            <testmysql4_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </testmysql4_write>
            <testmysql4_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </testmysql4_read>
        </resources>
        <blocks>
            <testmysql4>
                <class>Namespace_TestMySql4_Block</class>
            </testmysql4>
        </blocks>
        <helpers>
            <testmysql4>
                <class>Namespace_TestMySql4_Helper</class>
            </testmysql4>
        </helpers>
    </global>
</config>

忽略命名空间,有一个实际的名称,我选择忽略隐私问题。感谢您的所有帮助!!我只需要让这个后端工作。

编辑:

这是文件路径:

[root@x8dy-cvnm TestMySql4]# ls -R
.:
Block  controllers  etc  Helper  Model  sql

./Block:
Adminhtml

./Block/Adminhtml:
TestMySql4  TestMySql4.php

./Block/Adminhtml/TestMySql4:
Edit  Edit.php  Grid.php

./Block/Adminhtml/TestMySql4/Edit:
Form.php  Tab  Tabs.php

./Block/Adminhtml/TestMySql4/Edit/Tab:
Form.php

./controllers:
Adminhtml  IndexController.php

./controllers/Adminhtml:
TestMySql4Controller.php

./etc:
config.xml

./Helper:
Data.php

./Model:
Mysql4  TestMySql4.php

./Model/Mysql4:
TestMySql4  TestMySql4.php

./Model/Mysql4/TestMySql4:
Collection.php

./sql:
testmysql4_setup

./sql/testmysql4_setup:
mysql4-install-0.1.0.php

这是控制器:

<?php

class Namespace_TestMySql4_Adminhtml_TestMySql4Controller extends Mage_Adminhtml_Controller_Action
{

    protected function _initAction()
    {

        $this->loadLayout()->_setActiveMenu('testmysql4/items')->_addBreadcrumb(Mage::helper('adminhtml')->__('Items Manager'), Mage::helper('adminhtml')->__('Item Manager'));
        return $this;

    }

    public function indexAction()
    {

        //$this->_initAction();
        //$this->_addContent($this->getLayout()->createBlock('testmysql4/adminhtml_testmysql4'));
        //$this->renderLayout();
        echo 'hello'; //my goal was to see if it called this function at all (1st) step

    }

    public function editAction()
    {

        $testmysql4Id     = $this->getRequest()->getParam('id');
        $testmysql4Model  = Mage::getModel('testmysql4/testmysql4')->load($testmysql4Id);

        if ($testmysql4Model->getId() || $testmysql4Id == 0) {

            Mage::register('testmysql4_data', $testmysql4Model);

            $this->loadLayout();
            $this->_setActiveMenu('testmysql4/items');

            $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item Manager'), Mage::helper('adminhtml')->__('Item Manager'));
            $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item News'), Mage::helper('adminhtml')->__('Item News'));

            $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);

            $this->_addContent($this->getLayout()->createBlock('testmysql4/adminhtml_testmysql4_edit'))
                ->_addLeft($this->getLayout()->createBlock('testmysql4/adminhtml_testmysql4_edit_tabs'));

            $this->renderLayout();

        }

        else
        {

            Mage::getSingleton('adminhtml/session')->addError(Mage::helper('testmysql4')->__('Item does not exist'));
            $this->_redirect('*/*/');

        }

    }

    public function newAction()
    {

        $this->_forward('edit');

    }

    public function saveAction()
    {
        if ( $this->getRequest()->getPost() ) {
            try {
                $postData = $this->getRequest()->getPost();
                $testmysql4Model = Mage::getModel('testmysql4/testmysql4');

                $testmysql4Model->setId($this->getRequest()->getParam('id'))->setTitle($postData['title'])->setContent($postData['content'])->setStatus($postData['status'])->save();

                Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully saved'));
                Mage::getSingleton('adminhtml/session')->setTestMySql4Data(false);

                $this->_redirect('*/*/');
                return;

                } catch (Exception $e) {

                    Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
                    Mage::getSingleton('adminhtml/session')->setTestMySql4Data($this->getRequest()->getPost());
                    $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
                    return;

                }

        }

        $this->_redirect('*/*/');

    }

    public function deleteAction()
    {

        if( $this->getRequest()->getParam('id') > 0 ) {

            try {

                $testmysql4Model = Mage::getModel('testmysql4/testmysql4');

                $testmysql4Model->setId($this->getRequest()->getParam('id'))->delete();

                Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully deleted'));
                $this->_redirect('*/*/');

                } catch (Exception $e) {

                Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
                $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));

            }

        }

        $this->_redirect('*/*/');

    }
    /**
     * Product grid for AJAX request.
     * Sort and filter result for example.
     */
    public function gridAction()
    {

        $this->loadLayout();
        $this->getResponse()->setBody(
            $this->getLayout()->createBlock('testmysql4/adminhtml_testmysql4_grid')->toHtml()
        );

    }

}

2 个答案:

答案 0 :(得分:0)

在菜单中,您在URL中使用了这个:

<action>adminhtml/testmysql4</action>

Magento仅将第一个字符大写,因此您需要将类重命名为Namespace_TestMySql4_Adminhtml_Testmysql4Controller(并将文件名重命名为Testmysql4Controller.php以匹配)将操作URL大写,< / p>

<action>adminhtml/testMySql4</action>

传统上,URL都是小写的,因此第一个选项是常规的。

答案 1 :(得分:0)

与安装新扩展程序相同:

添加&#34; acl&#34;后,您必须与管理员联系/重新连接。字段以防止404错误。