Thứ Ba, 2 tháng 8, 2011

Create Module Prestashop Hello World

hi!
Today, i show you how to create module prestashop hello world.
1.First create folder "helloworld", then create file helloworld.php.
2.Write following code in your helloworld.php file:
<?php
class Helloworld extends Module
{
  /*is invoked automatically when a class is called. I've added my comments below.*/
     function __construct()
    {
        $this->name = 'helloworld';
$this->tab = 'Blocks';
  $this->version = 1.0;
  parent::__construct(); // The parent construct is required for translations
$this->page = basename(__FILE__, '.php');
$this->displayName = $this->l('Block Hello world');
$this->description = $this->l('Module Hello world');
    }
    /*And what about install() function? Well this is called by prestashop framework. It checks that your module is installed or not, you can modify hook names here. Please note that you have to write a function respective to your hooks defined and you are allowed to add multiple hooks*/
    function install()
    {
if (!parent::install())
           return false;
        if (!$this->registerHook('leftColumn'))
           return false;
        return true;
    }


/**
* Returns module content
*
* @param array $params Parameters
* @return string Content
*/
/*This is last step. We've defined registerHook('leftColumn'), so we've written following function. This method is called by front office to check your content path/variable/smarty etc.*/
    function hookLeftColumn($params)
    {
return $this->display(__FILE__, 'helloworld.tpl');
    }
}

3. Create file helloworld.tpl.
Write following code in your file helloworld.tpl:
<h2>Hello world</h2>


Thank you for your time. Please feel free to ask any question and feedback.

Không có nhận xét nào:

Đăng nhận xét