1

我正在创建一个用于在用户的 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>

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

4

1 回答 1

1

你为这个标签设置了 url <url>customer/newtab/</url> ,你应该有newtab某个地方的控制器,

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

     <routers>
        <customtabs>
            <use>standard</use>
            <args>
                <module>Fishpig_Customtabs</module>
                <frontName>customtabs</frontName>
            </args>
        </customtabs>
    </routers>
    
  2. 更改<url>customer/newtab/</url><url>customtabs/newtab</url>customtabs.xml 文件。还提出,

    <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. 因为你的代码应该是

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

并在那里放代码,

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" />
于 2013-07-10T06:54:45.587 回答