为什么Magento将我的自定义控制器重定向到" customer / account / login /"

时间:2015-05-27 15:25:27

标签: magento redirect controllers

我创建了我的控制器

<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

为什么会发生这种情况?如何禁用此行为?

1 个答案:

答案 0 :(得分:0)

尝试以下方法......

    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

我没有对此进行测试,但应该让你走上正确的道路。