Reputation: 581
I am currently in the development of a module prestashop and I meet a problem. I created a new hook for my module and I add an admin controller in my module that execute this hook I add the function that calls the hook and that uses a template. Except that the template does not appear I have an empty page. Here is the code I did:
My module:
<?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');
}
}
My AdminObjectifController:
<?php
class AdminObjectifController extends ModuleAdminController
{
public function __construct()
{
$this->bootstrap = true;
$this->table = 'objectifs';
$this->className = 'Objectif';
parent::__construct();
Hook::exec('displayAdminProductsExtra');
}
}
I do not see where the problem comes from ...
Thank you for your help
Upvotes: 2
Views: 1193
Reputation: 5748
This is not the right method to display a backoffice controller template.
Here is what you should try:
<?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();
}
}
Note that your admin-obj.tpl
file should be placed under views/templates/admin/admin-obj.tpl
inside your module.
Upvotes: 1