prestashop 自定义挂钩模块管理控制器
prestashop custom hook module admin controller
我目前正在开发一个模块 prestashop,但遇到了一个问题。我为我的模块创建了一个新的钩子,并在我的模块中添加了一个管理控制器来执行这个钩子我添加了调用钩子并使用模板的函数。除了没有出现模板外,我有一个空白页面。这是我做的代码:
我的模块:
<?php
if (!defined('_PS_VERSION_'))
exit;
/* Checking compatibility with older PrestaShop and fixing it */
if (!defined('_MYSQL_ENGINE_'))
define('_MYSQL_ENGINE_', 'MyISAM');
require_once(_PS_MODULE_DIR_.'blockobjectif/classes/Objectif.php');
class blockobjectif extends Module
{
public function __construct()
{
$this->name = 'blockobjectif';
$this->tab = 'front_office_features';
$this->version = '1.0';
$this->author = 'Athor Athor';
$this->bootstrap = true;
$this->need_instance = 0;
$this->ps_versions_compliancy['min'] = '1.5';
$this->ps_versions_compliancy['max'] = '1.6';
parent::__construct();
$this->displayName = $this->l('Objectifs');
$this->description = $this->l('Définie des objectifs aux clients');
}
public function install()
{
$sql = array();
include(dirname(__FILE__).'/sql/install.php');
foreach ($sql as $s)
if (!Db::getInstance()->execute($s))
return false;
$class = 'AdminObjectif';
$tab = new Tab();
$tab->class_name = $class;
$tab->module = $this->name;
$tab->id_parent = (int) Tab::getIdFromClassName('AdminParentCustomer');
$langs = Language::getLanguages(false);
foreach ($langs as $l) {
$tab->name[$l['id_lang']] = $this->l('Objectifs');
}
$tab->save();
return parent::install()
&& $this->registerHook('displayCustomerAccount')
&& $this->registerHook('displayAdminObjectifs');
}
public function uninstall($delete_params = true)
{
$sql = array();
include(dirname(__FILE__).'/sql/uninstall.php');
foreach ($sql as $s)
if (!Db::getInstance()->execute($s))
return false;
$moduleTabs = Tab::getCollectionFromModule($this->name);
if (!empty($moduleTabs)) {
foreach ($moduleTabs as $moduleTab) {
$moduleTab->delete();
}
}
if (!parent::uninstall())
return false;
return true;
}
public function hookDisplayCustomerAccount($params)
{
ddd($params);
}
public function hookDisplayAdminObjectifs($params)
{
return $this->display(__FILE__, 'admin-obj.tpl');
}
}
我的 AdminObjectifController:
<?php
class AdminObjectifController extends ModuleAdminController
{
public function __construct()
{
$this->bootstrap = true;
$this->table = 'objectifs';
$this->className = 'Objectif';
parent::__construct();
Hook::exec('displayAdminProductsExtra');
}
}
结果:
我看不出问题出在哪里...
感谢您的帮助
这不是显示后台控制器模板的正确方法。
以下是您应该尝试的方法:
<?php
class AdminObjectifController extends ModuleAdminController
{
public function __construct()
{
$this->bootstrap = true;
$this->table = 'objectifs';
$this->className = 'Objectif';
parent::__construct();
}
public function initContent()
{
$tpl = $this->context->smarty->createTemplate($this->getTemplatePath() . 'admin-obj.tpl', $this->context->smarty);
$tpl->assign(array(
'my_var' => "test"
));
$this->content .= $tpl->fetch();
parent::initContent();
}
}
请注意,您的 admin-obj.tpl
文件应放在模块内的 views/templates/admin/admin-obj.tpl
下。
我目前正在开发一个模块 prestashop,但遇到了一个问题。我为我的模块创建了一个新的钩子,并在我的模块中添加了一个管理控制器来执行这个钩子我添加了调用钩子并使用模板的函数。除了没有出现模板外,我有一个空白页面。这是我做的代码:
我的模块:
<?php
if (!defined('_PS_VERSION_'))
exit;
/* Checking compatibility with older PrestaShop and fixing it */
if (!defined('_MYSQL_ENGINE_'))
define('_MYSQL_ENGINE_', 'MyISAM');
require_once(_PS_MODULE_DIR_.'blockobjectif/classes/Objectif.php');
class blockobjectif extends Module
{
public function __construct()
{
$this->name = 'blockobjectif';
$this->tab = 'front_office_features';
$this->version = '1.0';
$this->author = 'Athor Athor';
$this->bootstrap = true;
$this->need_instance = 0;
$this->ps_versions_compliancy['min'] = '1.5';
$this->ps_versions_compliancy['max'] = '1.6';
parent::__construct();
$this->displayName = $this->l('Objectifs');
$this->description = $this->l('Définie des objectifs aux clients');
}
public function install()
{
$sql = array();
include(dirname(__FILE__).'/sql/install.php');
foreach ($sql as $s)
if (!Db::getInstance()->execute($s))
return false;
$class = 'AdminObjectif';
$tab = new Tab();
$tab->class_name = $class;
$tab->module = $this->name;
$tab->id_parent = (int) Tab::getIdFromClassName('AdminParentCustomer');
$langs = Language::getLanguages(false);
foreach ($langs as $l) {
$tab->name[$l['id_lang']] = $this->l('Objectifs');
}
$tab->save();
return parent::install()
&& $this->registerHook('displayCustomerAccount')
&& $this->registerHook('displayAdminObjectifs');
}
public function uninstall($delete_params = true)
{
$sql = array();
include(dirname(__FILE__).'/sql/uninstall.php');
foreach ($sql as $s)
if (!Db::getInstance()->execute($s))
return false;
$moduleTabs = Tab::getCollectionFromModule($this->name);
if (!empty($moduleTabs)) {
foreach ($moduleTabs as $moduleTab) {
$moduleTab->delete();
}
}
if (!parent::uninstall())
return false;
return true;
}
public function hookDisplayCustomerAccount($params)
{
ddd($params);
}
public function hookDisplayAdminObjectifs($params)
{
return $this->display(__FILE__, 'admin-obj.tpl');
}
}
我的 AdminObjectifController:
<?php
class AdminObjectifController extends ModuleAdminController
{
public function __construct()
{
$this->bootstrap = true;
$this->table = 'objectifs';
$this->className = 'Objectif';
parent::__construct();
Hook::exec('displayAdminProductsExtra');
}
}
结果:
我看不出问题出在哪里...
感谢您的帮助
这不是显示后台控制器模板的正确方法。
以下是您应该尝试的方法:
<?php
class AdminObjectifController extends ModuleAdminController
{
public function __construct()
{
$this->bootstrap = true;
$this->table = 'objectifs';
$this->className = 'Objectif';
parent::__construct();
}
public function initContent()
{
$tpl = $this->context->smarty->createTemplate($this->getTemplatePath() . 'admin-obj.tpl', $this->context->smarty);
$tpl->assign(array(
'my_var' => "test"
));
$this->content .= $tpl->fetch();
parent::initContent();
}
}
请注意,您的 admin-obj.tpl
文件应放在模块内的 views/templates/admin/admin-obj.tpl
下。