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

为什么Magento将我的自定义控制器重定向到“customer/account/login/”,magento,redirect,controllers,Magento,Redirect,Controllers,我创建了我的控制器 <modules> <Articul_Registration> <version>0.1.0</version> </Articul_Registration> </modules> <frontend> <routers> <registration> <use>stand

我创建了我的控制器

<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>
当我去

www.sitename/registration
Magento正在将我重定向到

www.sitename/customer/account/login
为什么会发生这种情况?如何禁用这种行为?

请尝试以下操作

    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


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

很高兴听到这个消息!请注意,这里重要的一点是,我在preDispatch方法中向打开的操作列表中添加了注册。这告诉magento不要重定向该操作。@espradley在我替换parent::preDispatch之前对我不起作用;使用Mage_Core_Controller_Front_Action::preDispatch;正如这里所建议的
    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);
        }
    }