Prestashop - 模块、SEO &网址和参数? [英] Prestashop - Module, SEO & URL and parameters?

查看:66
本文介绍了Prestashop - 模块、SEO &网址和参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为 Prestashop 制作了一个模块,它将根据参数 (&id=X) 中的给定 ID 显示内容.

I made a module for Prestashop that will display content based on the given ID in parameter (&id=X).

我想为此模块设置一个不错的网址.

I'd like to set a nice url for this module.

使用 SEO 和 URLS,我认为这是可能的,但它会在 url 中保留 ?id=X.

Using SEO and URLS, I see that it's possible, but it keeps the ?id=X in the url.

例如,如果我将模块的 url 定义为

For example, if I define the url to my module to be

/pretty-module

我将拥有相同的链接,但 ID 不同:

I will have the same links but with the different id :

/pretty-module?id=1
/pretty-module?id=23

我想做的是:

/pretty-module => will set id to 1
/even-prettier-module => will set id to 23

我在 SEO & 中没有看到参数"选项.后台中的 URLS 页面,所以我想知道是否可以这样做.

I didn't saw a "parameters" options in the SEO & URLS page in the Backoffice, so I'm wondering if it's possible to do this.

推荐答案

你需要hook到moduleRoutes,

you need to hook to moduleRoutes,

1) 在您的模块安装方法中:

1) in your module install method:

if (!parent::install()           
    || !$this->registerHook('moduleRoutes')
    || !$this->registerHook('displayFooter'))
       return false;

2) 创建对应的钩子

public function hookmoduleRoutes($params) {
    $routes = array();
    $routes['module-examplemodule-handler'] = array(
        'controller'=>'handler',
        'rule'=>'promo{/:code}',
        'keywords'=>array(
            'code'=>array(
                'regexp'=>'[\w]+',
                'param'=>'short_code'
            )
        ),
        'params'=>array(
            'fc'=>'module',
            'module'=>'examplemodule',
            'controller'=>'handler'
        )
    );

    return $routes;
}

模块可能有多个路由.约定是module-[MODULE_NAME]-[MODULE_CONTROLLER_NAME]

module may have multi routes. the convention is module-[MODULE_NAME]-[MODULE_CONTROLLER_NAME]

数组说明:

controller - handler (modules/examplemodule/controllers/front/handler.php)

controller - handler (modules/examplemodule/controllers/front/handler.php)

规则 - 花括号是参数.. 你可以从 http://example.com/admin/index.php?controller=AdminMeta

rule - curly braces are params.. you can get an idea from http://example.com/admin/index.php?controller=AdminMeta

关键字 - 在这里配置规则中定义的参数(花括号).

keywords - here you configure your params (curly braces) defined in the rule.

用法示例:http://example.com/promo/ADSGD

在控制器处理程序"中:

in controller 'handler':

$short_code = Tools::getValue('short_code');

在 prestashop 1.6 上测试

参考:

reference: https://books.google.co.il/books?id=BsSiBQAAQBAJ&pg=PT134&lpg=PT134&dq=prestashop+module+Routes+hook&source=bl&ots=JCb_4oz6el&sig=JwoQfIsOnJ49VJ752fEb01ivMZ8&hl=en&sa=X&ei=vH0QVePiDoXPaNSxgrAP&ved=0CEIQ6AEwBA#v=onepage&q=prestashop%20module%20Routes%20hook&f=false

这篇关于Prestashop - 模块、SEO &网址和参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆