Plugins can do just about anything. Create custom cron tasks, listen for events, create pages, create widgets, extend the API, etc., etc. If it's not a Module or a Payment Gateway, it's a plugin. So let's dig in.
Getting Started
Plugins follow the same MVC design pattern that Blesta adheres to. The plugin system is provided as a feature of the minPHP framework, Blesta simply defines the naming convention. For the purpose of this manual, the plugin name we'll refer to is my_plgn. Your plugin name will, of course, differ.
Info | ||
---|---|---|
| ||
A user will not be able to install two plugins with the same name, so try to use descriptive and non-generic terms for your plugin name. |
File Structure
Plugins are fully contained within their named plugin directory and placed in the /plugins/ directory. Below is the minimum required file structure for a plugin:
- /plugins/
- my_plgn/
- controllers/
- models/
- views/
- language/
- my_plgn_controller.php
- my_plgn_model.php
- my_plgn_plugin.php
- config.json (for version 3.1+)
- my_plgn/
my_plgn_controller.php is the plugin's parent controller. This controller can be used to add supporting methods for the other controllers to inherit. Similarly, my_plgn_model.php is the plugin's parent model and can be used to add supporting methods for the other models to inherit.
Because plugins inherit from the application stack their views default to the view directory defined for application. For this reason, you should always declare the view directory for the views within your plugin. The example below requires that you place all views (.pdt files) into /plugins/my_plgn/views/default/.
Tip | ||
---|---|---|
| ||
As of Blesta 4.12 we've included a useful tool to help developers get started and save time. Blesta's Extension Generator can be used to generate many the files necessary for a plugin and will create basic code with an option to include comments to help you understand each part of the code. |
Getting Started
Plugins follow the same MVC design pattern that Blesta adheres to. The plugin system is provided as a feature of the minPHP framework, Blesta simply defines the naming convention. For the purpose of this manual, the plugin name we'll refer to is my_plgn. Your plugin name will, of course, differ.
Info | ||
---|---|---|
| ||
A user will not be able to install two plugins with the same name, so try to use descriptive and non-generic terms for your plugin name. |
File Structure
Plugins are fully contained within their named plugin directory and placed in the /plugins/ directory. Below is the minimum required file structure for a plugin:
- /plugins/
- my_plgn/
- controllers/
- models/
- views/
- language/
- my_plgn_controller.php
- my_plgn_model.php
- my_plgn_plugin.php
- config.json (for version 3.1+)
- my_plgn/
my_plgn_controller.php is the plugin's parent controller. This controller can be used to add supporting methods for the other controllers to inherit. Similarly, my_plgn_model.php is the plugin's parent model and can be used to add supporting methods for the other models to inherit.
Because plugins inherit from the application stack their views default to the view directory defined for application. For this reason, you should always declare the view directory for the views within your plugin. The example below requires that you place all views (.pdt files) into /plugins/my_plgn/views/default/.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
<?php
class MyPlgnController extends AppController {
public function preAction() {
// Set the view directory to the default core view directory so that AppController preAction code uses the appropriate
// directory for the structure file
$this->structure->setDefaultView(APPDIR); | ||||||||
Code Block | ||||||||
| ||||||||
<?php class MyPlgnController extends AppController { public function preAction() { parent::preAction(); // Override default view directory with that of $this->view->view = "default";the plugin $this->structure>view->view = "default"; } } ?> |
...
Info | ||
---|---|---|
| ||
Use the Language library to help internationalize your plugin. Just create a language directory in your plugin, then a directory for each language (i.e. /plugins/my_pluginplgn/language/en_us/) and place your language files in there. See Translating Blesta for how to load, format, and use language definitions. |
...