覆盖Magento中的核心控制器
我试图覆盖Magento中核心控制器内的函数。所涉及的控制器是\magento\app\code\core\Mage\Customer\controllers\AccountController.php 我创建了以下文件: app/code/local/MyNameSpace/MyModule/etc/config.xml- app/code/local/MyNameSpace/MyModule/controllers/Customer/AccountController.php- app/etc/modules/MyNameSpace\u MyModule.xml-我不能将此作为链接发布,因为我的声誉低于10覆盖Magento中的核心控制器,magento,Magento,我试图覆盖Magento中核心控制器内的函数。所涉及的控制器是\magento\app\code\core\Mage\Customer\controllers\AccountController.php 我创建了以下文件: app/code/local/MyNameSpace/MyModule/etc/config.xml- app/code/local/MyNameSpace/MyModule/controllers/Customer/AccountController.php- app/et
有谁能告诉我我做错了什么,因为createPostAction函数没有被覆盖hello try be code config.xml是
<?xml version="1.0" encoding="utf-8"?>
<config>
<modules>
<Amit_Popuplogin>
<version>1.0.0</version>
</Amit_Popuplogin>
</modules>
<global>
<rewrite>
<popuplogin>
<from><![CDATA[#^/customer/account/#]]></from>
<to><![CDATA[/popuplogin/account/]]></to>
</popuplogin>
</rewrite>
</global>
<frontend>
<routers>
<popuplogin>
<use>standard</use>
<args>
<module>Amit_Popuplogin</module>
<frontName>popuplogin</frontName>
</args>
</popuplogin>
</routers>
</frontend>
</config>
控制器路径和控制器代码为
需要添加预剥离alwasys
<?php
require_once Mage::getModuleDir('controllers', 'Mage_Customer').DS.'AccountController.php';
class Amit_Popuplogin_AccountController extends Mage_Customer_AccountController
{
public function indexAction()
{
parent::indexAction();
}
protected $_cookieCheckActions = array('loginPost', 'createpost','ajaxloginPost');
protected $_validActions = array('create','login','logoutSuccess','forgotpassword','forgotpasswordpost','confirm','confirmation','resetpassword','resetpasswordpost');
protected $_customActions = array('signupformpopup','ajaxloginPost','ajaxCreate','ajaxForgotPassword','logout');
public function preDispatch()
{
$action = $this->getRequest()->getActionName();
if (preg_match('/^('.$this->_getCustomActions().')/i', $action))
{
$this->getRequest()->setActionName($this->_validActions[1]);
}
parent::preDispatch();
/**
* Parent check is complete, reset request action name to origional value
*/
if ($action != $this->getRequest()->getActionName())
{
$this->getRequest()->setActionName($action);
}
if (!$this->getRequest()->isDispatched()) {
return;
}
if (!preg_match('/^('.$this->_getValidActions().')/i', $action)) {
if (!$this->_getSession()->authenticate($this)) {
$this->setFlag('', 'no-dispatch', true);
}
} else {
$this->_getSession()->setNoReferer(true);
}
}
protected function _getValidActions()
{
return implode("|", array_merge($this->_validActions, $this->_customActions));
}
/**
* Gets custom action names and returns them as a pipe separated string
*
* @return string
*/
protected function _getCustomActions()
{
return implode("|", $this->_customActions);
}
public function ajaxloginPostAction()
{
if ($this->_getSession()->isLoggedIn()) {
$this->_redirect('*/*/');
return;
}
$session = $this->_getSession();
$result=array();
if ($this->getRequest()->isPost()) {
$login = $this->getRequest()->getPost('login');
if (!empty($login['username']) && !empty($login['password'])) {
try {
$session->login($login['username'], $login['password']);
if ($session->getCustomer()->getIsJustConfirmed()) {
$this->_welcomeCustomer($session->getCustomer(), true);
}
$result['success'] = true;
$result['redirecturl'] = Mage::getUrl('customer/account/edit');
$result['message'] = Mage::helper('customer')->__('You are successfully loged in.');
} catch (Mage_Core_Exception $e) {
switch ($e->getCode()) {
case Mage_Customer_Model_Customer::EXCEPTION_EMAIL_NOT_CONFIRMED:
/*$message = Mage::helper('customer')->__('This account is not confirmed. <a href="%s">Click here</a> to resend confirmation email.', Mage::helper('customer')->getEmailConfirmationUrl($login['username']));*/
$result['success'] = false;
$result['message'] = Mage::helper('customer')->__('This account is not confirmed.');
break;
case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD:
$message = $e->getMessage();
$result['success'] = false;
$result['message'] = Mage::helper('customer')->__($message);
break;
default:
$message = $e->getMessage();
$result['success'] = false;
$result['message'] = Mage::helper('customer')->__($message);
}
//$session->addError($message);
$session->setUsername($login['username']);
} catch (Exception $e) {
// Mage::logException($e); // PA DSS violation: this exception log can disclose customer password
}
} else {
//$session->addError($this->__('Login and password are required.'));
$result['success'] = false;
$result['message'] = Mage::helper('customer')->__('Login and password are required.');
}
}
$this->getResponse()->setBody(Zend_Json::encode($result));
//$this->_loginPostRedirect();
}
/**
* Forgot customer password action
*/
public function ajaxforgotPasswordPostAction()
{
$result= array();
$email = (string) $this->getRequest()->getPost('email');
if ($email) {
if (!Zend_Validate::is($email, 'EmailAddress')) {
$this->_getSession()->setForgottenEmail($email);
$result['success'] = false;
$result['message'] = $this->_getSession()->addError($this->__('Invalid email address.'));
$this->getResponse()->setBody(Zend_Json::encode($result));
//$this->_redirect('*/*/forgotpassword');
return;
}
/** @var $customer Mage_Customer_Model_Customer */
$customer = Mage::getModel('customer/customer')
->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
->loadByEmail($email);
if ($customer->getId()) {
try {
$newResetPasswordLinkToken = Mage::helper('customer')->generateResetPasswordLinkToken();
$customer->changeResetPasswordLinkToken($newResetPasswordLinkToken);
$customer->sendPasswordResetConfirmationEmail();
} catch (Exception $exception) {
$this->_getSession()->addError($exception->getMessage());
$this->_redirect('*/*/forgotpassword');
return;
}
}
$this->_getSession()
->addSuccess(Mage::helper('customer')->__('If there is an account associated with '.$email.' you will receive an email with a link to reset your password.', Mage::helper('customer')->htmlEscape($email)));
$result['success'] = true;
$result['message'] = Mage::helper('customer')->__('If there is an account associated with '.$email.' you will receive an email with a link to reset your password.');
$this->getResponse()->setBody(Zend_Json::encode($result));
// $this->_redirect('*/*/');
return;
} else {
$result['success'] = false;
$result['message'] = $this->_getSession()->addError($this->__('Please enter your email.'));
$this->getResponse()->setBody(Zend_Json::encode($result));
// $this->_redirect('*/*/forgotpassword');
return;
}
}
/**
* Customer logout action
*/
public function logoutAction()
{
$this->_getSession()->logout()
->setBeforeAuthUrl(Mage::getUrl());
$result= array();
$result['success'] = true;
$this->getResponse()->setBody(Zend_Json::encode($result));
// $this->_redirect('*/*/logoutSuccess');
}
}
?>
我认为您在app/code/local/MyNameSpace/MyModule/etc/config.xml中遗漏了很多内容 请尝试此代码 config.xml: Data.php: MyNameSpace\u MyModule.xml也可以。不需要改变..干杯 看一看@ 在config.xml中
.....
<modules>
<inchoo_coreextended before="Mage_Customer_AccountController"> Inchoo_Coreextended_Frontend_Customer</inchoo_coreextended>
</modules>
.....
我已经试过了,但还是不行。还有其他建议吗?
<?php
require_once "Mage/Customer/controllers/AccountController.php";
class MyNameSpace_MyModule_Customer_AccountController extends Mage_Customer_AccountController{
}
app/code/local/MyNameSpace/MyModule/Helper/
<?php
class MyNameSpace_MyModule_Helper_Data extends Mage_Core_Helper_Abstract
{
}
.....
<modules>
<inchoo_coreextended before="Mage_Customer_AccountController"> Inchoo_Coreextended_Frontend_Customer</inchoo_coreextended>
</modules>
.....