Plugins
Plugins in MV are classes for performing tasks that do not require managing a table in the database, as is the case with models.
Plugins are instantiated in the $mv object immediately upon its creation, and not like models using the lazy load principle.
Basic rules
- The plugin class must inherit from the Plugin class.
- The file must have a name like plugin_name.plugin.php and be located in the plugins folder in the root of the project.
- To activate a plugin, its class must be specified in the config/plugins.php file.
- The plugin object is available in the $mv -> plugin_name object.
- The plugin is constructed immediately upon creation of the $mv object.
//File plugins/cart.plugin.php
class Cart extends Plugin
{
private $items = [];
private $products_model;
public function __construct()
{
//Unlike models, the constructor can be supplemented
parent :: __construct();
//Product model object
$this -> products_model = new Products();
}
public function addItemToCart($id, $quantity)
{
...
}
}
//Example of using the plugin in a template file
$mv -> cart -> addItemToCart(56, 2);
Previous section
AJAX