繁体   English   中英

Magento-自定义模块网址

[英]Magento - Custom Module Url

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

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

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

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

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

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

抱歉,如果不够详细,我将很乐意在需要时发布更多代码。

提前致谢。

您可以将重写添加到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();

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

http://alanstorm.com/magento_dispatch_rewrites_intro

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

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

而且,如果您想使用管理员功能进行网址重写,则可以抛出此链接

您也可以通过“自定义网址重写”来实现。 例如:

request path: hello/world

target path: 'world'

这样,您就可以将系统的目标重写为起点。

希望这对您有帮助

最后这很简单。 不用费心为其创建重写,我只是将我的名字更改为“ hello”,然后创建了一个名为“ worldController”的控制器。

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

以自定义HTML网址链接访问自定义模块控制器路径

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM