URL link 用于 Prestashop 1.6 中的自定义模块
URL link for custom module in Prestashop 1.6
我目前正在开发自定义模块。
我想要的是有一个漂亮的URL,因为现在它看起来像这样:
domain.com/flower-deliveries?city=Hamburg&id_country=1&country=Germany
我已经在自定义模块 link 添加了一个新页面,页面名称是 flower-deliveries,但我仍然有 "hide".[=19= 必须的参数]
相反,对于上面的 link,我想要这样的 URL:
domain.com/flower-deliveries-1-Hamburg-Germany.html
我尝试了 2 种方法,但其中 none 有效..
第一个,是在我的控制器中添加一个 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 class:
'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'
)
),
使用该自定义规则时,link http://domain.com/flower-deliveries?city=Hamburg&id_country=1&country=Germany
在 http://domain.com/flower-deliveries?module_action=list
中进行了转换,但它不起作用,将我重定向到第一页。
有人能告诉我我做错了什么吗?
我花了几个小时阅读它应该如何完成,它应该就像上面的一样..
谢谢!
还原您所做的所有修改:)。
试试这个方法:
例如,这是核心模块文件rootofps/modules/vpages/vpages.php
class VPages extends Module {
public function __construct(){
$this->name = 'vpages';
$this->author = 'you';
$this->tab = 'front_office_features';
$this->version = '1.0.0';
$this->controllers = array('dpage');
parent::__construct();
}
// This is the function in your core module file (not in controller)
public function install(){
return parent::install() && $this->registerHook('moduleRoutes')
}
public function hookModuleRoutes($params){
$my_link = array(
'vpages' => array(
'controller' => 'dpage',
'rule' => 'flower-deliveries{-:id_country}{-:country}{-:city}.html',
'keywords' => array(
'id_country' => array('regexp' => '[0-9]+', 'param' => 'id_country'),
'country' => array('regexp' => '[\w]+', 'param' => 'country'),
'city' => array('regexp' => '[\w]+', 'param' => 'city'),
),
'params' => array(
'fc' => 'module',
'module' => 'vpages'
)
)
);
return $my_link;
}
}
现在控制器rootofps/modules/vpages/controllers/front/dpage.php
class VpagesDpageModuleFrontController extends ModuleFrontController {
public function init(){
parent::init();
$this->setTemplate('dapage.tpl');
}
}
现在视图 rootofps/modules/vpages/views/templates/front/dpage.tpl
id_country = {$smarty.get.id_country}<br>
country = {$smarty.get.country}<br>
city={$smarty.get.city}<br>
此 'skeleton' 以 100% 工作:),顺便说一句,请注意,如果您像这样 url mydomain.com/flower-deliveries?id_country=1&country=italy&city=rome
PrestaShop 将不会转换您的 url很明显url如你所愿。
但是像这样的 url mydomain.com/flower-deliveries-2-italy-rome.html
将是正确的路线 :)
我目前正在开发自定义模块。 我想要的是有一个漂亮的URL,因为现在它看起来像这样:
domain.com/flower-deliveries?city=Hamburg&id_country=1&country=Germany
我已经在自定义模块 link 添加了一个新页面,页面名称是 flower-deliveries,但我仍然有 "hide".[=19= 必须的参数]
相反,对于上面的 link,我想要这样的 URL:
domain.com/flower-deliveries-1-Hamburg-Germany.html
我尝试了 2 种方法,但其中 none 有效..
第一个,是在我的控制器中添加一个 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 class:
'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'
)
),
使用该自定义规则时,link http://domain.com/flower-deliveries?city=Hamburg&id_country=1&country=Germany
在 http://domain.com/flower-deliveries?module_action=list
中进行了转换,但它不起作用,将我重定向到第一页。
有人能告诉我我做错了什么吗? 我花了几个小时阅读它应该如何完成,它应该就像上面的一样..
谢谢!
还原您所做的所有修改:)。
试试这个方法:
例如,这是核心模块文件rootofps/modules/vpages/vpages.php
class VPages extends Module {
public function __construct(){
$this->name = 'vpages';
$this->author = 'you';
$this->tab = 'front_office_features';
$this->version = '1.0.0';
$this->controllers = array('dpage');
parent::__construct();
}
// This is the function in your core module file (not in controller)
public function install(){
return parent::install() && $this->registerHook('moduleRoutes')
}
public function hookModuleRoutes($params){
$my_link = array(
'vpages' => array(
'controller' => 'dpage',
'rule' => 'flower-deliveries{-:id_country}{-:country}{-:city}.html',
'keywords' => array(
'id_country' => array('regexp' => '[0-9]+', 'param' => 'id_country'),
'country' => array('regexp' => '[\w]+', 'param' => 'country'),
'city' => array('regexp' => '[\w]+', 'param' => 'city'),
),
'params' => array(
'fc' => 'module',
'module' => 'vpages'
)
)
);
return $my_link;
}
}
现在控制器rootofps/modules/vpages/controllers/front/dpage.php
class VpagesDpageModuleFrontController extends ModuleFrontController {
public function init(){
parent::init();
$this->setTemplate('dapage.tpl');
}
}
现在视图 rootofps/modules/vpages/views/templates/front/dpage.tpl
id_country = {$smarty.get.id_country}<br>
country = {$smarty.get.country}<br>
city={$smarty.get.city}<br>
此 'skeleton' 以 100% 工作:),顺便说一句,请注意,如果您像这样 url mydomain.com/flower-deliveries?id_country=1&country=italy&city=rome
PrestaShop 将不会转换您的 url很明显url如你所愿。
但是像这样的 url mydomain.com/flower-deliveries-2-italy-rome.html
将是正确的路线 :)