私はapp/code/core/Mage/Contacts/controllers/IndexController.phpをオーバーライドしようとしています。しかし、私はどこかで間違いを犯していると思う。私はすでにstackOverflowで似たような質問をしてきました。それに従ってください。しかし、問題はまだここにあります。Magento IndexControllerオーバーライドが動作しない
これが私のアプリ/コードです/ローカル/名前空間/ Customcontacts /コントローラ/ IndexController.php
<?xml version="1.0"?>
<config>
<modules>
<Namespace_Customcontacts>
<version>1.0.1</version>
</Namespace_Customcontacts>
</modules>
<frontend>
<routers>
<customcontacts>
<args>
<modules>
<Namespace_Customcontacts before="Mage_Contacts">Namespace_Customcontacts</Namespace_Customcontacts>
</modules>
</args>
</customcontacts>
</routers>
</frontend>
</config>
私はちょうどコア/メイジ/連絡先/コントローラ/ IndexController /アプリ/コードからコードをコピーしました。 phpをapp/code/local/Namespace/Customcontacts/controllers/IndexController.phpにコピーし、関数indexAction()に "Hello"を出力します。あなたのモジュールが登録されている場合
<?php
class Namespace_Customcontacts_IndexController extends Mage_Contacts_IndexController
{
const XML_PATH_EMAIL_RECIPIENT = 'contacts/email/recipient_email';
const XML_PATH_EMAIL_SENDER = 'contacts/email/sender_email_identity';
const XML_PATH_EMAIL_TEMPLATE = 'contacts/email/email_template';
const XML_PATH_ENABLED = 'contacts/contacts/enabled';
public function preDispatch()
{
parent::preDispatch();
if(!Mage::getStoreConfigFlag(self::XML_PATH_ENABLED)) {
$this->norouteAction();
}
}
public function indexAction()
{
echo "Hello";
// $this->loadLayout();
// $this->getLayout()->getBlock('contactForm')
// ->setFormAction(Mage::getUrl('*/*/post', array('_secure' => $this->getRequest()->isSecure())));
// $this->_initLayoutMessages('customer/session');
// $this->_initLayoutMessages('catalog/session');
// $this->renderLayout();
}
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')->__('Thanks for getting in touch, we will reply to your message as soon as we can.'));
$this->_redirect('*/*/');
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('*/*/');
return;
}
} else {
$this->_redirect('*/*/');
}
}
}
この問題を克服するために私を助けてください..すべての
感謝を自動的にロードされていないため、
としてコントローラファイルをインクルードする必要があります。しかし、system-> configuration-> advance-> Namespace_Customcontactsは有効です。 @Shaykant – Mayuri
@Mayuriあなたのフォルダ名がNamespaceでパス名が与えられているので、コントローラが見つからないので、名前を変更しようとしました – Shrikant
私の名前空間を "Namespace"で参照しています。私の名前空間は異なっています。いくつかの理由で私の名前空間を隠しています。しかし、あなたが提案した後、私はモジュール名をチェックしました。 @Shrikant – Mayuri