1

I have created and enabled a custom module in my magento store called 'Earnings' to allocate customers loyalty points. I declare the phtml file to use (template/earnings/earnings.phtml) in my earnings.xml as below

earnings.xml

<?xml version="1.0"?>
<layout version="0.1.0">
    <earnings_index_index>
        <reference name="content">
            <block type="earnings/earnings" name="earnings" />
        </reference>
    </earnings_index_index>
</layout>

I want the page that uses this template file to be linked from the customer account navigation when they log in (same place as my addresses/my billing agreements/my orders etc). In my local.xml i use addLink as below:

local.xml

<customer_account>
    <reference name="sidebar">
        <action method="unsetChild"><name>reorder</name></action>
        <block type="customer/account_navigation" name="customer_account_navigation" before="-" template="customer/account/navigation.phtml">
            <action method="addLink" translate="label" module="earnings"><name>earnings</name><path>earnings/earnings/</path><label>Earnings</label></action>
        </block>
        <remove name="tags_popular"/>
    </reference>
</customer_account>

Now when i log into the customer account the link is there,it goes to the url http://www.example.com/earnings/earnings but this gives my a 404 page not found

I am very new to magento and this is my first go at creating custom modules. Am i missing something or doing something in the wrong way?

1 Answer 1

1

This is the path reference that you are provided in a layout file

<path>earnings/earnings/</path>

This will set your link to this path http://www.website.com/earnings/earnings. When Magento looks for this path, it cannot find a valid controller definition. That is why it throws 404 error. So set your path to

  <path>earnings/</path>
         or
   <path>earnings/index/</path>

will solve your issue. Now the link looks like http://www.website.com/earnings/index/. You have defined your block for this specific URL. Note you have used earning_index_index handle in your layout file. This handle will be processed by Magento only when http://www.website.com/earnings/index/ URL get requested.

Note: In order to work this URL perfectly, you should have an IndexController.php is defined for your module and this file should hold this method.

public function indexAction() {

   $this->loadLayout();
   $this->renderLayout();
}

If this method and this file are not defined for your module, Magento will throw 404 error again.

Your Answer

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

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