0

I'm trying to create two separate registration pages. They need to be in their own model because one of the design requirements is having separate .phtml files. I have Magento 1.9 CE. I started by creating a new module, complete with its own template, layout, block, configuration and controller, and it worked without any problem. The I tried extending the Account Controller using the same module, following many tutorials which all talk about the same thing, but for some reason neither overriding of the indexAction is working, nor I'm able to call my new methods. I just get 404. Here's the code:

Code_PS.xml in /app/etc/modules

<?xml version="1.0"?>
<config>
    <modules>
        <Code_PS>
            <active>true</active>
            <codePool>local</codePool>
        </Code_PS>
    </modules>
</config>

code_ps.xml in /app/design/frontend/ps/marketplace/layout/

<?xml version="1.0"?>
<layout>
    <ps_account_registerimpressionist translate="label" module="ps">
        <label>Custom form</label>
        <reference name="root">
            <action method="setTemplate"><template>page/1column.phtml</template></action><!-- can be different -->
        </reference>        
        <reference name="content">
            <block type="core/template" name="ps" template="code_ps/registerimpressionist.phtml" /><!-- content of page -->
        </reference>
    </ps_account_registerimpressionist>
    <ps_account_registersponsor translate="label" module="ps">
        <label>Custom form</label>
        <reference name="root">
            <action method="setTemplate"><template>page/1column.phtml</template></action><!-- can be different -->
        </reference>        
        <reference name="content">
            <block type="core/template" name="ps" template="code_ps/registersponsor.phtml" /><!-- content of page -->
        </reference>
    </ps_account_registersponsor>
    <code_ps_customer_account_index>
        <update handle="customer_account_index"/>           
    </code_ps_customer_account_index>
</layout>

config.xml from /app/code/local/Code/PS/etc/

<?xml version="1.0"?>
<config>
    <modules>
        <Code_PS>
            <version>0.2.0</version>
        </Code_PS>
    </modules>
    <frontend>
        <routers>
            <customer>
                <use>standard</use>
                <args>
                    <modules>
                        <Code_PS before="Mage_Customer">
                            Code_PS
                        </Code_PS>
                    </modules>
                </args>
            </customer>
        </routers>
        <layout>
            <updates>
                <code_ps>
                    <file>code_ps.xml</file><!-- frontend layout file -->
                </code_ps>
            </updates>
        </layout>
    </frontend>
</config>

and finally, AccountController.php from /app/code/local/Code/PS/controllers/

<?php
require_once 'Mage/Customer/controllers/AccountController.php';
class Code_PS_AccountController extends Mage_Customer_AccountController
{
    public function indexAction()
    {
        //no custom codes. 
        //parent::indexAction();
    }


    public function registerimpressionistAction(){ 
        if ($this->_getSession()->isLoggedIn()) {
            $this->_redirect('*/*');
            return;
        }

        $this->loadLayout();
        $this->_initLayoutMessages('customer/session');
        $this->renderLayout();
    }


    public function registersponsorAction(){
        $this->loadLayout();
        $this->_initLayoutMessages('core/session'); //this will allow flash messages
        $this->renderLayout();
    }
    }
}

any help would be appreciated

1 Answer 1

1

Issue1: Spacing issue

In config.xml

<Code_PS before="Mage_Customer">
                            Code_PS
                        </Code_PS> 

Please put this code in one line:

 <Code_PS  before="Mage_Customer">Code_PS</Code_PS>

Like:

<frontend>
        <routers>
            <customer>
                <args>
                    <modules>
                        <Code_PS  before="Mage_Customer">Code_PS</Code_PS>
                    </modules>
                </args>
            </customer>
        </routers>
........

Layout file not working:

May be layout update is not working: you need to remove code from config.xml.Need to put codes of codes_ps code at local.xml or customer.xml.

Remove:

<layout>
            <updates>
                <code_ps>
                    <file>code_ps.xml</file><!-- frontend layout file -->
                </code_ps>
            </updates>
        </layout>

preDispatch function:

As per as magento system,before any action of AccountController dispatch magento is check check it valued or not.So you need to add your action to dispatch event.

Code:

<?php
require_once 'Mage/Customer/controllers/AccountController.php';
class Code_PS_AccountController extends Mage_Customer_AccountController
{ 
  public function preDispatch()
    {

        $action = $this->getRequest()->getActionName();
        $ExitsopenActions = array(
            'create',
            'login',
            'logoutsuccess',
            'forgotpassword',
            'forgotpasswordpost',
            'resetpassword',
            'resetpasswordpost',
            'confirm',
            'confirmation'
        );
        $newOpenAction=array('registerimpressionist','registersponsor');

        $allActions=array_merge($ExitsopenActions,$newOpenAction);

        /* check custom action */
        $Custompattern = '/^(' . implode('|', $newOpenAction) . ')/i';


        if (preg_match($Custompattern, $action)) {
            /* if match then set Current action to create for skip  parent::preDispatch(); */
            $this->getRequest()->setActionName('create');
        }
        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;
           }

        $mypattern = '/^(' . implode('|', $allActions) . ')/i';

        if (!preg_match($mypattern, $action)) {
            if (!$this->_getSession()->authenticate($this)) {
                $this->setFlag('', 'no-dispatch', true);
            }
        } else {
            $this->_getSession()->setNoReferer(true);
        }

    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.