Magento IndexController覆盖不起作用

时间:2015-06-11 09:58:20

标签: magento

我很确定我在这里做错了,但我现在已经看了几个小时的代码了,我似乎无法修复它。

所以这就是问题所在: 我想在提交联系表单后覆盖/ core / Contacts / controllers中的IndexController以重定向到自定义页面。当我在核心文件中进行更改时它会起作用,但我们都知道这不是可行的方法。

我的config.xml(app / code / local / Namespace / ContactRedirect / etc / config.xml ):     

<config>    
    <frontend>
        <routers>
            <contacts>
                <args>
                    <modules>
                        <contactredirect before="Mage_Contacts">Namespace_ContactRedirect</contactredirect>
                    </modules>
                </args>
            </contacts>
        </routers>
    </frontend>
</config>

我的IndexController(app / code / local / Namespace / ContactRedirect / controllers / IndexController.php ):

<?php

require_once(Mage::getModuleDir("controllers", "Mage_Contacts").DS."IndexController.php");

class Namespace_ContactRedirect_IndexController extends Mage_Contacts_IndexController {

public function postAction() {
    $post = $this->getRequest()->getPost();
    if ( $post ) {
        $translate = Mage::getSingleton('core/translate');
        /* @var $translate Mage_Core_Model_Translate */
        $translate->setTranslateInline(false);
        try {
            $postObject = new Varien_Object();
            $postObject->setData($post);

            $error = false;

            if (!Zend_Validate::is(trim($post['name']) , 'NotEmpty')) {
                $error = true;
            }

            if (!Zend_Validate::is(trim($post['comment']) , 'NotEmpty')) {
                $error = true;
            }

            if (!Zend_Validate::is(trim($post['email']), 'EmailAddress')) {
                $error = true;
            }

            if (Zend_Validate::is(trim($post['hideit']), 'NotEmpty')) {
                $error = true;
            }

            if ($error) {
                throw new Exception();
            }
            $mailTemplate = Mage::getModel('core/email_template');
            /* @var $mailTemplate Mage_Core_Model_Email_Template */
            $mailTemplate->setDesignConfig(array('area' => 'frontend'))
                ->setReplyTo($post['email'])
                ->sendTransactional(
                    Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE),
                    Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER),
                    Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT),
                    null,
                    array('data' => $postObject)
                );

            if (!$mailTemplate->getSentSuccess()) {
                throw new Exception();
            }

            $translate->setTranslateInline(true);

            Mage::getSingleton('customer/session')->addSuccess(Mage::helper('contacts')->__('Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.'));
            //$this->_redirect('*/*/');
            $this->getResponse()->setRedirect(Mage::getUrl('contact-form', array('_secure' => true)));

            return;
        } catch (Exception $e) {
            $translate->setTranslateInline(true);

            Mage::getSingleton('customer/session')->addError(Mage::helper('contacts')->__('Unable to submit your request. Please, try again later'));
            //$this->_redirect('*/*/');
            $this->getResponse()->setRedirect(Mage::getUrl('contact-form', array('_secure' => true)));
            return;
        }

    } else {
        //$this->_redirect('*/*/');
        $this->getResponse()->setRedirect(Mage::getUrl('contact-form', array('_secure' => true)));
    }
}

}

编辑:禁用Magento缓存。

4 个答案:

答案 0 :(得分:0)

您可能在config.xml标记中的<modules>中犯了错误,

<config>    
    <frontend>
        <routers>
            <contacts>
                <args>
                    <modules>
                        <Namespace_ContactRedirect before="Mage_Contacts">Namespace_ContactRedirect</Namespace_ContactRedirect>
                    </modules>
                </args>
            </contacts>
        </routers>
    </frontend>
</config>

答案 1 :(得分:0)

嘿,有/ etc / config.xml文件有问题,请检查两次我有相同的代码运行完美。让我知道如果仍然有任何查询,也在这里给我发消息

由于

答案 2 :(得分:0)

我发现了...... 我不得不说声抱歉,感谢所有试图帮助我的人。 这是在etc / config.xml顶部的一个愚蠢的错字。

来了:

而不是<?xml version="1.0"?><?xml version="1.0?> 看到缺少的“1.0之后......

我责备我的编辑没有标记它:P

下次我发布整个文件......

再次非常感谢@All和sry浪费你的时间......

答案 3 :(得分:0)

<config>
	<modules>
		<Namespace_ContactRedirect>
			<version>0.1.0</version>
				</Namespace_ContactRedirect>
</modules>
<frontend>
<routers>
	<contacts>
		<args>
			<modules>
				<contactredirect before="Mage_Contacts">Namespace_ContactRedirect</contactredirect>
</modules>
</args>
</contacts>
</routers>
</frontend>
</config>