in this tutorial you will learn 

  • plugin's library file role as controller 
  • how to load model, library ..
  • how to prepare plugin param for template file to use if plugin has parameter (width,height limit).
  • how to set website settings for plugin template if needed.
  • how to load constant languages for plugin's tpl template file
  • index function that returns smarty fetch html data

 

front library file


File name: /front/libraries/plugin_key.php

front library file is actually behaving like controller in MVC during plugin load for page it being loaded as library. This file name should be same as plugin key

 

Example code below show default plugin latest_products_v2 library file includes  
download

  • loading model example and using model function latest_product using plugin information param values,(for example get latest 10 products)
  • prepare plugin param for template using php function unserialize  
    $this->data["param"]=unserialize($plugin["param"]);
  • setting website settings for plugin template  
     
    $this->data["settings"]=$this->CI->data["settings"];
  • load constant languages for plugin's tpl template file 
    $this->data["L"]=$this->CI->data["L"];
  • how to use 2 different html template version for differen page positions.

    if(in_array($plugin["position"],array("left","right"))){
    $template_file='plugins/latest_products_v2.tpl';
    }else{
    $template_file='plugins/latest_products_center_v2.tpl';
    }

  • index function that returns smarty fetch html data to CI page controller

 

/// default plugin latest products ///

class latest_products_v2 {

function __construct() {
$this->CI =& get_instance() ;
}

function index($plugin){ 

$this->CI->load->model('product_model');
$this->data["L"]=$this->CI->data["L"];
$this->data["settings"]=$this->CI->data["settings"];
$this->data["param"]=unserialize($plugin["param"]);

/// plugin latest product ///
$this->data["latest_products"]=$this->CI->product_model->latest_product($this->data["param"]["sample"]["limit"])->result_array();
/// plugin latest product///

if(in_array($plugin["position"],array("left","right"))){

$template_file='plugins/latest_products_v2.tpl';
}else{

$template_file='plugins/latest_products_center_v2.tpl';
}


return $this->CI->smarty->fetch($template_file,$this->data);
}


}

/// default plugin latest products ///



Posted by: Müslüm ÇEN
Date Added: 21/02/2016
Last Update:




Not Commented Yet !
Please login in order to comment . Login