Prestashop 自定义路由模块不起作用

Prestashop custom route module no work

我尝试为我的 prestashop 模块重写 url。 我想 http://shop.dev/perso/id_customer?token=sdfgh5678terzs

所以我有模块文件

rootofps/modules/hfn_front/hfn_front.php

<?php
if (!defined('_PS_VERSION_'))
  exit;

class hfn_front extends Module
{

    public function __construct()
    {
        $this->name = 'hfn_front';
        $this->tab = 'others';
        $this->version = '1.0.0';
        $this->author = 'Johan VIVIEN';
        $this->need_instance = 0;
        $this->secure_key = Tools::encrypt($this->name);
        $this->ps_versions_compliancy = array('min' => '1.6.1', 'max' => _PS_VERSION_); 
        $this->bootstrap = true;
        $this->ps_versions_compliancy['min'] = '1.5.0.1';   

        parent::__construct();

        $this->displayName = $this->l('HFN Front');
        $this->description = $this->l('test d\'un module de front');

        $this->confirmUninstall = $this->l('Are you sure you want to uninstall?');

    }

    public function install()
    {

        if (Shop::isFeatureActive())
            Shop::setContext(Shop::CONTEXT_ALL);

        if ( parent::install() &&
             $this->registerHook('ModuleRoutes') )
            return true;

        return false;

    }

    public function uninstall()
    {
        /* Deletes Module */
        if (parent::uninstall())
            return true;

        return false;
    }


    public function hookModuleRoutes()
    {
        return array(
                'hfn_front' => array(
                    'controller' => 'perso',
                    'rule' =>  '{/:controller}{/:id_customer}',
                    'keywords' => array(
                        'id_customer'  => array('regexp' => '[0-9]+', 'param' => 'id_customer'),
                        'controller' => array('regexp' => '[\w]+',  'param' => 'controller')
                    ),
                    'params' => array(
                        'fc' => 'module',
                        'module' => 'hfn_front',
                        'controller' => 'perso'
                    )
                )

            );
    }   
}

我的前端模块控制器是

rootofps/modules/hfn_front/controllers/front/perso.php

<?php


class hfn_frontPersoModuleFrontController extends ModuleFrontController
{
    public function initContent()
    {
        parent::initContent();

        $error['error'] = 'no found file';

        echo json_encode($error);

        exit();
    }   
}

但是当我去 http://shop.dev/perso/1?token=sdfgh5678terzs

时,前面有一个 404 页面

感谢您的帮助

我认为数组的键是错误的。它应该是'module-{module_name}-{controller}。也不确定规则是否接受控制器名称作为变量。尝试:

public function hookModuleRoutes()
{
    return array(
            'module-hfn_front-perso' => array(
                'controller' => 'perso',
                'rule' =>  'perso{/:id_customer}',
                'keywords' => array(
                    'id_customer'  => array('regexp' => '[0-9]+', 'param' => 'id_customer'),
                ),
                'params' => array(
                    'fc' => 'module',
                    'module' => 'hfn_front',
                )
            )
        );
}