我目前正在开发一个自定义模块。 我要的是有一个很好的网址,因为现在它看起来像这样:Prestashop中的自定义模块的URL链接1.6
domain.com/flower-deliveries?city=Hamburg&id_country=1&country=Germany
我已经添加了一个新的页面链接到自定义模块,页面的名称是花交付,但我仍然有我必须“隐藏”的参数。
相反,该链接的上面,我想这样的URL:
domain.com/flower-deliveries-1-Hamburg-Germany.html
我试过2种方法,但他们没有工作..
第一个,就是增加一个hookModuleRoutes在我的控制器,就像下面:
public function hookModuleRoutes($params)
{
return array(
'module-vpages-dpage' => array(
'controller' => 'dpage',
'rule' => 'flower-deliveries{-:id_country}{-:country}{-:city}.html',
'keywords' => array(
'id_country' => array('regexp' => '[_a-zA-Z0-9_-]+', 'param' => 'id_country'),
'city' => array('regexp' => '[\w]+', 'param' => 'city'),
'country' => array('regexp' => '[\w]+', 'param' => 'country')
),
'params' => array(
'fc' => 'module',
'module' => 'vpages',
'controller' => 'dpage'
)
)
);
}
然后,在控制器上安装:
$this->registerHook('moduleRoutes');
这并没有工作,所以我试图重写Dispatcher类,加入了自定义模块路线:
'module-vpages-dpage' => array(
'controller' => 'dpage',
'rule' => 'flower-deliveries{-:id_country}{-:country}{-:city}.html',
'keywords' => array(
'id_country' => array('regexp' => '[0-9]+', 'param' => 'id_country'),
'city' => array('regexp' => '[\w]+', 'param' => 'city'),
'country' => array('regexp' => '[\w]+', 'param' => 'country'),
),
'params' => array(
'fc' => 'module',
'module' => 'vpages',
'controller' => 'dpage'
)
),
当使用自定义规则,链接http://domain.com/flower-deliveries?city=Hamburg&id_country=1&country=Germany
在http://domain.com/flower-deliveries?module_action=list
被tranformed,它没”没有工作,并将我重定向到第一页。
有人能告诉我我做错了什么吗? 我已经花了数小时阅读它应该如何完成,它应该就像上面的那些。
谢谢!
您的第一种方法是可以的,但它需要在您的模块类中,而不是在控制器中。在你的规则中,你已经定义了'rule'=>'flower-deliveries { - :id_country} { - :country} { - :city} .html' -Germany'。您在国家之前使用城市,但按照不同的顺序定义其规则。 – TheDrot
是的,我知道,我修改了模块,在模块文件中有钩子,但仍然没有任何内容..它不显示为假设.. – rosuandreimihai
定义您的规则,就像这个''rule'=>'flower-deliveries- {:id_country} - {:country} - {:city} .html''并查看它是否有效。我测试了你的第一个解决方案,然后PrestaShop抛出异常,但是这种方式对我很有用。 – TheDrot