Q: A custom frontend controller will extend which one of the following classes?

All Action Controller need Mage_Core_Controller_Front_Action as an ancestor.

The best example of this in action is a simple HelloWorld module that is configured with routes and has a Create Action Controller for the routes.

Directory Structure:

app/code/local/nodwell/Helloworld/Block
app/code/local/nodwell/Helloworld/controllers
app/code/local/nodwell/Helloworld/etc
app/code/local/nodwell/Helloworld/Helper
app/code/local/nodwell/Helloworld/Model
app/code/local/nodwell/Helloworld/sql

We need a configuration file (PATH: app/code/local/nodwell/Helloworld/etc/config.xml):


<config>    
    <modules>
        <nodwell_Helloworld>
            <version>1.0.0</version>
        </nodwell_Helloworld>
    </modules>
</config>

and a modules file to activate our module (PATH: app/etc/modules/nodwell_Helloworld.xml):


<config>
    <modules>
        <nodwell_Helloworld>
            <active>true</active>
            <codePool>local</codePool>
        </nodwell_Helloworld>
    </modules>
</config>

Now, the module exists, and we can begin to add the code to make it do stuff. We need to configure a route in the config.xml. The route turns a URL into an Action Controller and a method. In our case, it will act on URLs that start with /helloworld, as in http://magento.nodwell.net/helloworld/*. So, add a frontend routers section to the config.xml:


<config>    
    <modules>
        <nodwell_Helloworld>
            <version>1.0.0</version>
        </nodwell_Helloworld>
    </modules>
    <frontend>
        <routers>
            <helloworld>
                <use>standard</use>
                <args>
                    <module>nodwell_Helloworld</module>
                    <frontName>helloworld</frontName>
                </args>
            </helloworld>
        </routers>  
    </frontend>
</config>
 

Now, we create the actual Action Controller (PATH: app/code/local/nodwell/Helloworld/controllers/IndexController.php):

class nodwell_Helloworld_IndexController extends Mage_Core_Controller_Front_Action {        
    public function indexAction() {
        echo 'Hello Index!';
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *