用户的我的帐户magento中的错误404

时间:2013-07-10 06:23:41

标签: magento module account

我正在创建一个模块,用于在User的myaccount中创建新标签。我已经成功添加了一个名为“我的特殊产品”的标签。 问题是,当我点击该标签时,它会重定向到404错误页面。我无法解决问题。

我的布局xml(customtabs.xml)代码是:

<?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>

我的模板页面位于template \ customer \ newtab \ newtab.phtml

我的模块“Customtabs”的config.xml是:

<?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>

任何人都可以帮我解决问题。

1 个答案:

答案 0 :(得分:1)

您将此标签的网址设为<url>customer/newtab/</url> 所以,你应该在某处拥有newtab的控制器,

  1. 首先,您需要在模块的config.xml中添加<routers>部分,将其放在<frontend>中。

     <routers>
        <customtabs>
            <use>standard</use>
            <args>
                <module>Fishpig_Customtabs</module>
                <frontName>customtabs</frontName>
            </args>
        </customtabs>
    </routers>
    
  2. 在customtabs.xml文件中将<url>customer/newtab/</url>更改为<url>customtabs/newtab</url>。 还说,

    <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>
    
  3. 在code / local / Fishpig / Customtabs / controllers / NewtabController.php

  4. 创建一个控制器
  5. 因为你的代码应该是

    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();
        }
    
    }
    
  6. 添加阻止文件为app / code / local / Fishpig / Customtabs / Block / Customtabs.php

  7. 并放置代码,

    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');
    
        }
    }
    

    并在customtabs.xml文件中更改块类型

    <block type="customtabs/customtabs" name="customer_newtab_newtab" template="customer/newtab/newtab.phtml" />