...
Code Block |
---|
language | php |
---|
title | /modules/my_module/my_module.php |
---|
linenumbers | true |
---|
|
<?php
class MyModule extends Module {
...
public function uninstall($module_id, $last_instance) {
#
# TODO: Place uninstallation logic here
#
}
}
?> |
Upgrade Logic
When the version of your code differs from that recorded within Blesta a user may initiate an upgrade, which will invoke your module's upgrade() method.
The $current_version is the version currently installed. That is, the version that will be upgraded from.
Code Block |
---|
language | php |
---|
title | /modules/my_module/my_module.php |
---|
linenumbers | true |
---|
|
<?php
class MyModule extends Module {
...
public function upgrade($current_version) {
#
# TODO: Place upgrade logic here
#
}
}
?> |
Error Passing
Blesta facilitates error message passing through the use of the Input component. Simply load the Input component into your module and set any errors you encounter using Input::setErrors(). The setErrors() method accepts an array of errors. This can be a multi-dimensional array (in the case of multiple errors triggered for the same input or criteria) or a single dimensional array. The first dimension should be the name of the input that triggered the error. The second dimension, if necessary, is used to identify the type of error encountered.
Code Block |
---|
language | php |
---|
title | /module/my_module/my_module.php |
---|
linenumbers | true |
---|
|
<?php
class MyModule extends Module {
public function __construct() {
Loader::loadComponents($this, array("Input"));
}
...
public function upgrade($current_version) {
// Ensure new version is greater than installed version
if (version_compare($this->version, $current_version) < 0) {
$this->Input->setErrors(array(
'version' => array(
'invalid' => "Downgrades are not allowed."
)
);
return;
}
}
}
?> |
Module Methods
Now that we've looked at some of the basic of creating a module, let's take a look at all of the required methods each module must implement: Module Methods.