duanpuqi9965 2017-08-18 08:32
浏览 54
已采纳

Prestashop自定义路由模块没有工作

i try to have a rewrite url for my prestashop module. I want http://shop.dev/perso/id_customer?token=sdfgh5678terzs

so i have module file

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

            );
    }   
}

And my front module controller is

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

But i have an 404 page on the front when i go to http://shop.dev/perso/1?token=sdfgh5678terzs

Thanks for your help

  • 写回答

1条回答 默认 最新

  • duancanjiu3754 2017-08-18 09:16
    关注

    I think the key for the aray is wrong. It should be 'module-{module_name}-{controller}. Also not sure the rule accepts the controller name as variable. Try:

    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',
                    )
                )
            );
    } 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建