【问题标题】:Magento - custom module add 2nd pageMagento - 自定义模块添加第二页
【发布时间】:2014-06-12 12:11:34
【问题描述】:

我已经为此工作了好几天,我为 Magento 创建了一个自定义模块,以使用本指南添加客户帐户页面 - http://alanstorm.com/magento_create_customer_page

所以我得到了 www.mydomain.com/portfolio,它使用我的布局文件中的代码指向自定义模块:

<portfolio_index_index>
            <update handle="customer_account" />
            <reference name="root">
                    <action method="setTemplate"><template>page/1column.phtml</template></action>
            </reference>
            <reference name="my.account.wrapper">
                <block type="core/template" name="cadaptor_portfolio_content" template="cadaptor_portfolio.phtml"/>           
            </reference>
</portfolio_index_index>

我现在正尝试在 www.mydomain.com/portfolio/add 或类似的模块中添加第二个页面,实际 URL 并不重要。

所以我将这个添加到布局文件中:

<action method="addLink">
    <name>portfolio_add</name>
    <path>portfolio/add</path>
    <label>Add To Your Portfolio</label>
</action>

效果很好...链接出现在菜单中并转到它应该去的地方。

还添加了:

<portfolio_add>
            <update handle="customer_account" />
            <reference name="root">
                    <action method="setTemplate"><template>page/1column.phtml</template></action>
            </reference>
            <reference name="my.account.wrapper">
                <block type="core/template" name="cadaptor_portfolio_add" template="cadaptor_portfolio_add.phtml"/>           
            </reference>
</portfolio_add>

我已经创建并上传了 _add 模板文件,但除了 404 错误之外什么都没有,如果有人能在正确的方向上推动我,我将不胜感激。

【问题讨论】:

    标签: php magento


    【解决方案1】:

    首先,添加页面的布局句柄应该是 portfolio_index_add 而不是 portfolio_add
    并在您的IndexController.php 中添加以下方法:

    public function addAction()
    {
        $this->loadLayout();
        $this->renderLayout();
    }
    

    你的路径应该是“portfolio/index/add”

    【讨论】:

    • 工作就像一个魅力!我会尽快接受你的回答,非常感谢。唯一的问题是页面在投资组合/索引/添加上工作,这是可以预期的吗?我可以更改我的链接,所以它不是问题,但我不明白索引来自哪里
    • index 是控制器名称,而 add 是操作,是的,这很正常。如果你想保留你的路径投资组合/添加,那么你必须创建一个控制器 AddControllers.php 并在其中使用 indexAction()。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多