Jump to content

The following module(s) were not installed properly era_widget


namnguyen2091

Recommended Posts

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`');
    }
    
}

Link to comment
Share on other sites

Your fuctions like __construct, install(), etc. aren't public.

 

 

 

 

Furthermore your (public) function hookdisplayHeader() should have a capital D -> hookDisplayHeader()

(functions are NOT case sensitive in php, but PrestaShop code standards expect it:

http://doc.prestashop.com/display/PS16/Coding+Standards#CodingStandards-Method/Functionnames

 

Also, use Era_Widget as your Class name, with First capitals, or even better EraWidget, without '_')

http://doc.prestashop.com/display/PS16/Coding+Standards#CodingStandards-Objects/Classes

 

Hope this helps,

pascal.

  • Like 1
Link to comment
Share on other sites

Your fuctions like __construct, install(), etc. aren't public.

 

 

 

 

Furthermore your (public) function hookdisplayHeader() should have a capital D -> hookDisplayHeader()

(functions are NOT case sensitive in php, but PrestaShop code standards expect it:

http://doc.prestashop.com/display/PS16/Coding+Standards#CodingStandards-Method/Functionnames

 

Also, use Era_Widget as your Class name, with First capitals, or even better EraWidget, without '_')

http://doc.prestashop.com/display/PS16/Coding+Standards#CodingStandards-Objects/Classes

 

Hope this helps,

pascal.

"Your fuctions like __construct, install(), etc. aren't public" I see many __construct functions in modules in default source wrote like I wrote above :v

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...