Magento 1.9 – Custom Layout Not Loading for Custom Module

layoutmagento-1.9modulerender

I have created a custom module.

Below is my app/etc/modules/Php_CardReload.xml

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

Below is my app/code/local/Php/CardReload/etc/config.xml

<config>
    <modules>
        <Php_CardReload>
            <version>0.0.1</version>
        </Php_CardReload>
    </modules>
    <global>
    </global>
    <frontend>
        <routers>
            <reload>
                <use>standard</use>
                <args>
                    <module>Php_CardReload</module>
                    <frontName>reload</frontName>
                </args>
            </reload>
        </routers>
    </frontend>
    <layout>
        <updates>
            <cardreload>
                <file>php_cardreload.xml</file>
            </cardreload>
        </updates>
    </layout>
</config>

Below is my controller

<?php
    class Php_CardReload_MtoMController extends Mage_Core_Controller_Front_Action {
        function reloadCardAction(){
        $this->loadLayout();
            $this->renderLayout();

        }
    }
?>

Below is my php_cardreload.xml

<?xml version="1.0"?>
<layout version="0.0.1">
<default>    
        <reference name="top.links">
            <block type="checkout/links" name="checkout_cart_link">
                <action method="addCartLink"></action>
                <action method="addCheckoutLink"></action>
            </block>
        </reference>
        <reference name="right">
            .
            .
            .
        </reference>
    </default>
    <cardreload_mtom_reloadcard>
        <reference name="content">
            <!--<block type="cardreload/cardreload" name="cardreload" template="cardreload/cardreload.phtml" />-->
            <block type="core/template" name="cardreload" as="reload" template="page/card-summary.phtml"/>
        </reference>
    </cardreload_mtom_reloadcard>
</layout>

But the page.card-summary.phtml is not rendering.
Also no log captured on system.log.

Best Answer

Some mistakes which I can see in your files;

1. layout file declaration is placed in wrong place

Layout definition should be inside frontend node. ie code should look like

<frontend>
    <routers>
        <cardreload>
            <use>standard</use>
            <args>
                <module>Php_CardReload</module>
                <frontName>reload</frontName>
            </args>
        </cardreload>
    </routers>
    <layout>
        <updates>
            <cardreload>
                <file>php_cardreload.xml</file>
            </cardreload>
        </updates>
    </layout>
</frontend>

2. Router configuration is wrong

your router unique identifier should be cardreload instead of reload. See above for the change.

3. controller class is wrong

Your controller class should be Php_CardReload_MtomController instead of Php_CardReload_MtoMController. Make sure path to your controller is app\code\local\Php\CardReload\controllers\MtomController.php instead of app\code\local\Php\CardReload\controllers\MtoMController.php

3. Controller action method is wrong.

It should be reloadcardAction instead of reloadCardAction.

After all changes made, please do clear your cache. Let me know whether it works or not