php - Prestashop custom route module no work -
i try have rewrite url prestashop module. want http://shop.dev/perso/id_customer?token=sdfgh5678terzs
so 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 sure want 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 front module controller
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 have 404 page on front when go http://shop.dev/perso/1?token=sdfgh5678terzs
thanks help
i think key aray wrong. should 'module-{module_name}-{controller}. not sure rule accepts controller name 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', ) ) ); }
Comments
Post a Comment