I am creating a module for creating new tab in User's myaccount. I have successfully added a tab named "My Special Products". Problem is that when i click on that tab it's redirect to 404 error page. I am not able to getting the problem.
My layout xml(customtabs.xml) code is:
<?xml version="1.0"?>
<layout version="0.1.0">
<customer_account>
<!-- Mage_Review -->
<reference name="customer_account_navigation" before="-" >
<action method="addLink" translate="label" module="customer">
<name>newtab</name>
<url>customer/newtab/</url>
<label>My Special Products</label>
</action>
</reference>
</customer_account>
<customer_account translate="label">
<label>Customer My Special Products</label>
<update handle="customer_account"/>
<reference name="my.account.wrapper">
<block type="customer/newtab_newtab" name="customer_newtab_newtab" template="customer/newtab/newtab.phtml"/>
</reference>
</customer_account>
</layout>
My template page is at template\customer\newtab\newtab.phtml
My config.xml for module "Customtabs" is :
<?xml version="1.0"?>
<config>
<modules>
<Fishpig_Customtabs>
<version>0.1.0</version>
</Fishpig_Customtabs>
</modules>
<global>
<blocks>
<customtabs>
<class>Fishpig_Customtabs_Block</class>
</customtabs>
</blocks>
<models>
<customtabs>
<class>Fishpig_Customtabs_Model</class>
</customtabs>
</models>
<helpers>
<customtabs>
<class>Fishpig_Customtabs_Helper</class>
</customtabs>
</helpers>
</global>
<frontend>
<layout>
<updates>
<customtabs>
<file>Customtabs.xml</file>
</customtabs>
</updates>
</layout>
</frontend>
<adminhtml>
<layout>
<updates>
<customtabs>
<file>customtabs.xml</file>
</customtabs>
</updates>
</layout>
<events>
<catalog_product_save_after>
<observers>
<fishpig_save_product_data>
<type>singleton</type>
<class>customtabs/observer</class>
<method>saveProductTabData</method>
</fishpig_save_product_data>
</observers>
</catalog_product_save_after>
</events>
</adminhtml>
</config>
Any one can help me where is the problem.
You set url for this tab as <url>customer/newtab/</url>
so, you should have controller of newtab
somewhere,
First you need to add <routers>
part in your module's config.xml, put this in <frontend>
.
<routers>
<customtabs>
<use>standard</use>
<args>
<module>Fishpig_Customtabs</module>
<frontName>customtabs</frontName>
</args>
</customtabs>
</routers>
change <url>customer/newtab/</url>
to <url>customtabs/newtab</url>
in customtabs.xml file.
also put,
<customtabs_newtab_index>
<update handle="customer_account"/>
<reference name="my.account.wrapper">
<block type="customer/newtab_newtab" name="customer_newtab_newtab" template="customer/newtab/newtab.phtml"/>
</reference>
</customtabs_newtab_index>
create a controller at code/local/Fishpig/Customtabs/controllers/NewtabController.php
in that your code should be
class Fishpig_Customtabs_NewtabController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
if(!Mage::getSingleton('customer/session')->isLoggedIn())
{
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('customer/account'));
return false;
}
$this->loadLayout();
$this->_initLayoutMessages('customer/session');
$this->getLayout()->getBlock('head')->setTitle($this->__('My Special Products'));
$this->renderLayout();
}
}
Add a block file as app/code/local/Fishpig/Customtabs/Block/Customtabs.php
and put there code,
class Fishpig_Customtabs_Block_Customtabs extends Mage_Core_Block_Template
{
public function _prepareLayout()
{
return parent::_prepareLayout();
}
public function getCustomtabs()
{
if (!$this->hasData('customtabs')) {
$this->setData('customtabs', Mage::registry('customtabs'));
}
return $this->getData('customtabs');
}
}
and change your block type in your customtabs.xml file
<block type="customtabs/customtabs" name="customer_newtab_newtab" template="customer/newtab/newtab.phtml" />