【问题标题】:Magento - Custom Module UrlMagento - 自定义模块网址
【发布时间】:2013-09-13 00:58:54
【问题描述】:

我有一个更改模块网址的请求。

例如,假设网址是 www.example.com/world

我需要网址是 www.example.com/hello/world

我知道在模块配置 xml 中,您可以将节点更改为您喜欢的任何内容(只要它是唯一的),但不允许添加 /hello/

 <frontend>
    <routers>
        <anexample>
            <use>standard</use>
            <args>
                <module>An_Example</module>
                <frontName>hello/world</frontName>
            </args>
        </anexample>
    </routers>
 </frontend>

有谁知道如何做到这一点?一些示例代码甚至是正确方向的一点将不胜感激!

对不起,如果这不够详细,如果需要,我很乐意发布更多我的代码。

提前致谢。

【问题讨论】:

    标签: magento url-rewriting module


    【解决方案1】:

    您可以将重写添加到 Magento 的 URL 重写管理器中。未测试以下代码。但希望它有所帮助。

    Mage::getModel('core/url_rewrite')
    ->setIsSystem(0)
    ->setStoreId($storeId)   
    ->setOptions('RP')  
    ->setIdPath('index.php?cat=c' . $categoryId . '_' . $this->strip($data['name']) . '.html')
    ->setTargetPath($categoryModel->getUrlPath() . '.html')// Put the actual path
    ->setRequestPath('index.php?cat=c' . $categoryId . '_' . $this->strip($data['name']) . '.html') // put the path you want to display
    ->save();
    

    【讨论】:

      【解决方案2】:

      在这里,我可以给您提供解决方案的想法,它肯定会对您有所帮助

      <?xml version="1.0"?>
      <config>
        <global>
         <rewrite>
            <some_unique_name_to_identify_this_rewrite>
              <from><![CDATA[#^/from_this/#]]></from>
              <to>/to_this/</to>
            </some_unique_name_to_identify_this_rewrite>
         </rewrite>
      </global>
      </config>
      

      如果你想用管理员功能重写 url,你可以去 throw this link

      您想要实现的目标也可以通过自定义 URL 重写来完成。例如:

      request path: hello/world
      
      target path: 'world'
      

      通过这种方式,您将成为系统重写的起点。

      希望这对你有帮助

      【讨论】:

        【解决方案3】:

        最后这很简单。而不是去为它创建一个重写的麻烦,我只是将我的frontname更改为'hello'然后创建了一个名为'worldController'的控制器

        然后在我的 indexController 中,我只是重定向到 */world

        【讨论】:

          【解决方案4】:

          请参阅 Allan Storm 以下关于 Magento 重写的文章

          http://alanstorm.com/magento_dispatch_rewrites_intro

          【讨论】:

          • 不幸的是,这对我没有多大帮助。我已经尝试在 xml 中使用 影响不大。通常会导致 404 或根本不重定向。我确定我只是遗漏了一些明显的东西,但我已经盯着它看了很长时间,这一切都变成了胡言乱语。
          【解决方案5】:

          访问自定义模块控制器路径作为自定义 HTML Url 链接

          http://domain.com/index.php/customwallpaper/index/create/

          将被改写为

          http://domain.com/index.php/fotomural-personalizado.html

          core_url_rewrite 表中插入以下数据以进行 url 重写

          Mage::getModel('core/url_rewrite')
              ->setStoreId(1)   
              ->setIdPath('customwallpaper')
              ->setRequestPath('fotomural-personalizado.html')
              ->setTargetPath('customwallpaper/index/create') // Put the actual Controller path
              ->setIsSystem(1)
              ->save();
          

          -或-

          运行下面的sql查询

          INSERT INTO `core_url_rewrite` 
          (`url_rewrite_id`, `store_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`, `category_id`, `product_id`) 
          VALUES ('7', '1', 'customwallpaper', 'fotomural-personalizado.html', 'customwallpaper/index/create', '1', NULL, NULL, NULL, NULL);
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2014-07-09
            • 1970-01-01
            • 2012-08-28
            • 2014-05-22
            • 1970-01-01
            相关资源
            最近更新 更多