为什么Magento将我的自定义控制器重定向到“customer / account / login /”(Why Magento redirect my custom controller to “

系统教程 行业动态 更新时间:2024-06-14 16:57:18
为什么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/registration

Magento正在重定向我

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/registration

Magento is redirecting me to

www.sitename/customer/account/login

Why 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.

更多推荐

本文发布于:2023-04-12 20:36:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/f2a19e58e1c3f960a1d660837527a417.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   控制器   重定向   customer   Magento

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!