I tried to use the code below to create a new module but I got an error as the same title. Please help me check!
<?php
if (!defined('_PS_VERSION_')) exit;
include_once(_PS_MODULE_DIR_ . 'era_widget/widgetModel.php');
/**
* Description of era_widget
*
* @author nguye_000
*/
class era_widget extends Module {
private $_html = '';
function __construct() {
$this->name = 'era_widget';
$this->tab = 'other';
$this->version = '1.0';
$this->author = 'Nam Nguyen';
$this->need_instance = 1;
$this->secure_key = Tools::encrypt($this->name);
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Era Widget');
$this->description = $this->l('Display widgets for sidebar or something');
}
function install() {
if (parent::install() && $this->registerHook('displayHeader')){
$res = $this->createTable();
if ($res) {
$this->installSamples();
}
return $res;
}
return false;
}
function uninstall() {
if (parent::uninstall()) {
$res = $this->deleteTable();
return (bool)$res;
}
return false;
}
function hookdisplayHeader() {
return $this->display(__FILE__, 'frontend.tpl');
}
private function createTable() {
$sql = "DROP TABLE IF EXISTS " . _DB_PREFIX_ . "`awidget`;CREATE TABLE " . _DB_PREFIX_ . "`awidget` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`key` varchar(255) NOT NULL,
`value` longtext NOT NULL,
`area` text NOT NULL COMMENT 'where to contains widget',
`position` int(5) NOT NULL COMMENT 'order',
`parent` bigint(20) NOT NULL COMMENT 'wrapper is parent or not',
PRIMARY KEY (`id`),
KEY `meta_key` (`key`)
) ENGINE=". _MYSQL_ENGINE_ ." DEFAULT CHARSET=utf8;";
$res = (bool) Db::getInstance()->execute($sql);
return $res;
}
private function installSamples() {
$sql = "insert into ". _DB_PREFIX_ . "`awidget`(`id`,`key`,`value`,`area`,`position`,`parent`) "
. "values (1,'textwidget','a:2:{s:5:\"title\";s:14:\"The first text\";s:7:\"content\";s:232:\"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\";}','widget-area-sample',1,0);";
DB::getInstance()->execute($sql);
}
private function deleteTable() {
return Db::getInstance()->execute('DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'awidget`');
}
}