Jump to content

[Solved] My modules does not load the template to render


Aegidius

Recommended Posts

Hello :)

 

I created and installed a module and I can see it in the live edit position window, but it does not render any content.

 

This is my module.

 

<?php
if (!defined('_PS_VERSION_')) {
exit();
}
require __DIR__ . '/DbManager.class.php';
class AdvancedSearchModule extends Module
{
public function __construct()
{
	$this->name		  = 'advancedsearchmodule';
	$this->tab		   = 'Search';
	$this->version	   = 1.0;
	$this->author		= 'Egidio Caprino';
	$this->need_instance = 0;
	parent::__construct();
	$this->displayName = $this->l('Advanced Search');
	$this->description = $this->l('Allow user to search for attributes.');
}
public function install()
{
	if (!parent::install() || !$this->registerHook('top') || !$this->registerHook('displayHome')) {
		return false;
	}
	return true;
}
public function hookTop($params)
{
	global $smarty;
	$smarty->assign('features', $this->getFeatures());
	return $this->display(__FILE__, 'top.tpl');
}
public function hookDisplayHome($params)
{
	global $smarty;
	$features = $this->getFeatures();
	$smarty->assign('features', $features);
	$this->display(__FILE__, 'home.tpl');
}
public function uninstall()
{
	if (!parent::uninstall())
	{
		Db::getInstance()->Execute('DELETE FROM ' . _DB_PREFIX_ . 'advancedsearchmodule');
	}
	parent::uninstall();
}
private function getFeatures()
{
	$lang = (int) $this->context->language->id;
	$db	 = DbManager::getInstance();
	$query  = 'SELECT id_feature, name FROM ' . _DB_PREFIX_
			. 'feature_lang WHERE id_lang = ' . $lang
			. ' ORDER BY name ASC';
	$result = $db->query($query);
	$features = array();
	while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
		$features[$row[0]] = array(
			'name'   => $row[1],
			'values' => array()
		);
	}
	$query = 'SELECT ' . _DB_PREFIX_ . 'feature_value.id_feature_value, '
		   . _DB_PREFIX_ . 'feature_value_lang.value FROM '
		   . _DB_PREFIX_ . 'feature_value INNER JOIN '
		   . _DB_PREFIX_ . 'feature_value_lang ON ' . _DB_PREFIX_
		   . 'feature_value.id_feature_value = ' . _DB_PREFIX_
		   . 'feature_value_lang.id_feature_value WHERE id_lang = '
		   . $lang . ' AND ' . _DB_PREFIX_
		   . 'feature_value.id_feature = %s ORDER BY '
		   . _DB_PREFIX_ . 'feature_value_lang.value ASC';
	foreach ($features as $id_feature => $name) {
		$result = $db->query(sprintf($query, $id_feature));
		while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
			$features[$id_feature]['values'][$row[0]] = $row[1];
		}
	}
	return $features;
}
}

 

This is my home.tpl file placed in the same root of the file above.

 

<h1> HOOK HOME </h1>

Edited by Aegidius (see edit history)
Link to comment
Share on other sites

in installation function use:

!$this->registerHook('top')

!$this->registerHook('header')

 

and create functions:

 

public function hookHeader($params){}

public function hookTop($params){}

 

 

can you check it??

Link to comment
Share on other sites

I did it. I can transplant the module in the header and in the top. I cannot transplant it the center column (displayHome).

 

I checked and the code under the hookDisplayHome function is executed. It just does not dysplay the home.tpl. This file is in the module dir. Is that position correct? I don't understand.

Link to comment
Share on other sites

I did it but it still not working. The code in that function is executed but the home.tpl is not diplayed.

 

Is the problem in this line '$this->display(__FILE__, 'home.tpl');'? The home.tpl file is in the same directory of the module class.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...