为什么Magento将我的自定义控制器重定向到“customer / account / login /”(Why Magento redirect my custom controller to “customer/account/login/”)
我创建了我的控制器
<modules> <Articul_Registration> <version>0.1.0</version> </Articul_Registration> </modules> <frontend> <routers> <registration> <use>standard</use> <args> <module>Articul_Registration</module> <frontName>registration</frontName> </args> </registration> </routers> </frontend>和控制器文件
require_once 'Mage/Customer/controllers/AccountController.php'; class Articul_Registration_RegistrationController extends Mage_Customer_AccountController { public function indexAction() { echo("Nice!"); } }当我去
www.sitename/registrationMagento正在重定向我
www.sitename/customer/account/login为什么会发生这种情况?如何禁用此行为?
I created my controller
<modules> <Articul_Registration> <version>0.1.0</version> </Articul_Registration> </modules> <frontend> <routers> <registration> <use>standard</use> <args> <module>Articul_Registration</module> <frontName>registration</frontName> </args> </registration> </routers> </frontend>And controller file
require_once 'Mage/Customer/controllers/AccountController.php'; class Articul_Registration_RegistrationController extends Mage_Customer_AccountController { public function indexAction() { echo("Nice!"); } }When I go to
www.sitename/registrationMagento is redirecting me to
www.sitename/customer/account/loginWhy is this happening and how do I disable this behaviour?
最满意答案
试试以下......
require_once 'Mage/Customer/controllers/AccountController.php'; class Articul_Registration_RegistrationController extends Mage_Customer_AccountController { public function registrationAction() { echo("Nice!"); } } /** * Action predispatch * * Check customer authentication for some actions */ public function preDispatch() { // a brute-force protection here would be nice parent::preDispatch(); if (!$this->getRequest()->isDispatched()) { return; } $action = $this->getRequest()->getActionName(); $openActions = array( 'create', 'login', 'logoutsuccess', 'forgotpassword', 'forgotpasswordpost', 'resetpassword', 'resetpasswordpost', 'confirm', 'confirmation', 'registration', ); $pattern = '/^(' . implode('|', $openActions) . ')/i'; if (!preg_match($pattern, $action)) { if (!$this->_getSession()->authenticate($this)) { $this->setFlag('', 'no-dispatch', true); } } else { $this->_getSession()->setNoReferer(true); } }基本上您不想使用indexAction(),因为这已经在父控制器中定义,并且因为您使用注册作为您的URL。 您需要导航到yourdomain.com/customer/registration
我没有对此进行测试,但应该让你走上正确的道路。
Try the following...
require_once 'Mage/Customer/controllers/AccountController.php'; class Articul_Registration_RegistrationController extends Mage_Customer_AccountController { public function registrationAction() { echo("Nice!"); } } /** * Action predispatch * * Check customer authentication for some actions */ public function preDispatch() { // a brute-force protection here would be nice parent::preDispatch(); if (!$this->getRequest()->isDispatched()) { return; } $action = $this->getRequest()->getActionName(); $openActions = array( 'create', 'login', 'logoutsuccess', 'forgotpassword', 'forgotpasswordpost', 'resetpassword', 'resetpasswordpost', 'confirm', 'confirmation', 'registration', ); $pattern = '/^(' . implode('|', $openActions) . ')/i'; if (!preg_match($pattern, $action)) { if (!$this->_getSession()->authenticate($this)) { $this->setFlag('', 'no-dispatch', true); } } else { $this->_getSession()->setNoReferer(true); } }Basically you don't want to use indexAction() because this is already defined in the parent controller, and because you using registration as your URL. You'll want to navigate to yourdomain.com/customer/registration
I didn't test this, but should get you going on the right path.
更多推荐
发布评论