General principles of plugins

The purpose of applying plugins in MV is the necessity of using additional objects and methods that don't need the full functionality of models and admin panel interface.

  1. The class of plugin should be inherited from the class "Plugin" with the name of "name.plugin.php" format.
  2. The file of a class should be located in "/plugins/" folder in the project root.
  3. The table of a plugin should match the name of a plugin.
  4. To activate the plugin its name should be specified in "config/plugins.php" file.
  5. The object of a plugin will be accessible in "$mv -> plugin_name" object.

Built-in properties and objects

  • table - the current table of a plugin, matches the name of a plugin in the lower case (for the plugin to have a real SQL table is not mandatory)
  • registry - an object of access to settings from configuration files, read more in System settings
  • db - object - the database manager performing Direct queries to a database

Available methods

  • All methods of Query constructor section
  • resizeImage($image, $width, $height) - resize the image, returns "img" tag
  • cropImage($image, $width, $height) - resize and crop the image, returns "img" tag (read more Files and images section)
  • extractImages($value [, $no-comments]) - extraction of images from a "multi_images" field
  • getFirstImage($value) - extraction of the first image from an array of the image ("multi_images" datatype)

Sample

//File location "plugins/cart.plugin.php"
//Plugin name is added into "config/plugins.php" file

class Cart extends Plugin
{
    //Array of cart product as "product_id" => "product_quantity"
    private $items = array();

    private $products_model;

    public function __construct()
    {
        //The constructor can be extended
        parent :: __construct();

        //Object of products model
        $this -> products_model = new Products();
    }
 
    public function addItemToCart($id, $quantity)
    {
        $this -> items[$id] = $quantity;

        ...
    }
 
    ...
}

//Example of use 
$mv -> cart -> addItemToCart(56, 2);