...
Code Block | ||||
---|---|---|---|---|
| ||||
<?php if ( !defined( '_PS_VERSION_' ) ) exit; class MyModule extends Module { public function __construct() { $this->name = 'mymodule'; $this->tab = 'Test'; $this->version = 1.0; $this->author = 'Firstname Lastname'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l( 'My module' ); $this->description = $this->l( 'Description of my module.' ); } public function install() { if ( parent::install() == false ) return false; return true; } } ?> |
...
Code Block |
---|
$this->name = 'mymodule'; |
Assigns a 'name' attribute to our class' instance.
Code Block |
---|
$this->tab$this->tab = 'Test'; $this->version = 1.0; $this->author = 'TestPrestaShop'; |
Assigns a 'tab' attribute to our class' instanceThis section assign a handful of attributes to the class instance (this
):
- A 'name' attribute. This is an internal identifier, so make it unique, without special characters or spaces, and keep it lower-case.
- A 'tab' attribute. This is the title for the table that shall contain this module in PrestaShop's back-office modules list. You may use an existing name, such as
Products
,Blocks
orStats
, or a custom, as we did here. In this last case, a new table will be created with your title. - Version number for the module, displayed in the modules list.
- An 'author' attribute. This is displayed in the PrestaShop modules list.
Code Block |
---|
$this->version>need_instance = 1.0; |
Version number for the module, displayed in the modules listNeed_instance flag indicates whether to load the module's class when displaying the "Modules" page in the back-office. If set at 0, the module will not be loaded, and therefore will spend less resources to generate the page module. If your modules needs to display a warning message in the "Modules" page, then you must set this attribute to 1.
Code Block |
---|
parent::__construct(); |
...
Code Block |
---|
public function install()
{
if ( parent::install() == false )
return false;
return true;
return ( parent::install() AND $this->registerHook( 'top' ) AND $this->registerHook( 'header' ) );
}
|
This code checks:
- the value returned by the
Module
class'install()
method. If it returns true
As it is, this method is useless, since all it does is check the value returned by the Module
class' install()
method. Moreover, if we hadn't created that method, the superclass' method would have been called instead anyway, making the end result identical.
Nevertheless, we must mention this method, because it will be very useful once we have to perform checks and actions during the module's installation process: creating SQL tables, copying files, creation configuration variables, etc.
...