【问题标题】:Magento Custom URLMagento 自定义网址
【发布时间】:2013-03-14 15:18:35
【问题描述】:

我创建了一个新模块来替换客户/帐户菜单并有一个链接 www.mysite.com/account

我现在想将登录、注册和其他页面更改为 www.mysite.com/account/login 等

而不是恢复到客户/帐户/登录等

最好的方法是什么?

这是我目前制作的 config.xml 代码......

<?xml version="1.0"?>
<config>
  <modules>
    <SquareNetMedia_MyAccount>
      <version>0.1.0</version>
    </SquareNetMedia_MyAccount>
  </modules>
  <frontend>
    <routers>
      <myaccount>
        <use>standard</use>
          <args>
            <module>SquareNetMedia_MyAccount</module>
            <frontName>account</frontName>
          </args>
      </myaccount>
    </routers>
        <layout>
          <updates>
            <myaccount>
              <file>myaccount.xml</file>
            </myaccount>
          </updates>
        </layout>
  </frontend>
  <global>

    <helpers>
      <myaccount>
        <class>SquareNetMedia_MyAccount_Helper</class>
      </myaccount>
    </helpers>
    <blocks>
      <myaccount>
        <class>SquareNetMedia_MyAccount_Block</class>
      </myaccount>
    </blocks>
  </global>
</config> 

【问题讨论】:

  • Magento 使用以下标准 url 格式:site.com/modulename/controller/action 如果您想要不同的 url 格式,然后尝试使用 magento 重写或使用一些 .htaccess 规则

标签: magento e-commerce magento-1.7


【解决方案1】:

将您的文件更改为如下所示:

 <frontend>
 <routers>
 <myaccount>
    <use>standard</use>
      <args>
        <module>SquareNetMedia_MyAccount</module>
        <frontName>account</frontName>
      </args>
  </myaccount>
  <customer>
    <args>
      <modules>
        <SquareNetMedia_MyAccount before="Mage_Customer_AccountController">SquareNetMedia_MyAccountr</SquareNetMedia_MyAccount>
      </modules>
    </args>
  </customer>

然后在模块的控制器文件夹中创建一个名为 AccountController.php 的新控制器文件

<?php
require_once Mage::getModuleDir('controllers','Mage_Customer').DS.'AccountController.php';
class SquareNetMedia_MyAccount_AccountController extends Mage_Customer_AccountController{
}

现在您可以覆盖函数

 public function loginAction(){
 #Here you can do what you need I think
 }

我希望这是正确的,如果不清楚,请告诉我。和平。

【讨论】:

  • 谢谢 - 我已经更改了我的代码,但现在我得到的只是 404 错误而不是 Account Controller.php 我之前使用的是 IndexController.php,它加载了新布局,但现在当你修改为上面的代码不起作用
猜你喜欢
  • 2013-09-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-08
  • 2019-01-04
  • 1970-01-01
相关资源
最近更新 更多