in this tutorial you will learn 

  • inserting plugin information into database and plugin information.
  • inserting or registering plugin's section if needed.
  • inserting meta link information if the plugin has meta link for front pages.
  • creating table for the plugin if plugin extends existing cart21. 

File name: /admin/controllers/plugins/plugin_key.php

 

Register plugin info (required)


code below shows an example of resigtering plugin info to database

function index(){

/// Register plugin info ///

    $param["default"]=array(

    "limit"=>10,

    );    

     $data=array(

     "title"=>"Plugin Title - latest product",

     "publisher"=>"Developer Title",

     "plugin_type_id"=>2,

     "pub_email"=>"support@developerdomain.com",

     "p_key"=>"plugin_key", /// same as library file name

     "content"=>"description about plugin",

    "status"=>0,

     "manage_link"=>"admin/anycontroller",

    "param"=> serialize($param)

     );

    ///

$check_plugin=$this->db->where("p_key",$data["p_key"])->get("plugin"); 

if($check_plugin->num_rows==0 ){

$this->db->insert("plugin",$data);

$plugin_id=$this->db->insert_id();

redirect("admin/plugin");

}else{

echo "already installed ! new files uploaded All Plugins";

}

/// Register plugin info ///

}

 

 

Plugin info attributes 

      "p_key"=>"plugin_key",  represent unique key for the plugin and  some plugin file name shoul be same name 

  • /admin/controllers/plugins/plugin_key.php
  • /admin/libraries/plugins/plugin_key.php
  • /front/libraries/plugins/plugin_key.php

     "title"=>"Plugin title ", visible to admin user and it can be modified under the plugin edit form

     "publisher"=>"plugin developer name it is a text",

     "plugin_type_id" =>2: plugin_type_id is constant already registered by default cart21 and it represents plugin category and enable admin user to filter plugins by its category related (template, modules, payment, shipping,order,language, default) 

     "pub_email"=>"support@developerdomain.com", plugin developer's  email 

     "content"=>"description about plugin",

    "status"=>0, status should be 0 (zero) at first  after inastallation if you open (activate) modification file will write changes otherwise it is probable to have conflict

    "positional"=>0, when set 1 it mean this plugin assignable to page position on the plugin edit from page posions will be visible (example latest product is positional is 1 it could be assigned to any page positions)

    "manage_link"=>"admin/anycontroller", it means if this plugin has management page in the admin panel you set here the link after it will be visible on the left menu of admin panel under plugins. 

    "param"=> serialize($param) parameter that plugin's use for settings  ( example; width, height, limit etc.)  

 

 

 

Register section(s) (optional)


Registering section is optional when the plugin has admin controller to manage data you have to register section(s) permission_sections db table for system to load languages and permissions for admin user groups.

Example : below sample multiple section addinginside index() function,  if section already exists it would't register new one. 

//// SECTIN INFO ////

$sections[]=array(

"name"=>"controller_name",

"class"=>"controller_name",

"file_name"=>"controller_name.php"

);

foreach($sections as $m){

if(! $this->db->get_where("permission_sections",array("name"=>"download_release"))->num_rows ){

$this->db->insert("permission_sections",$m);

echo "new section added";

}else{

echo "new section already exist";

}

}

  //// SECTIN INFO ////

 

 

Register meta(s) (optional)


Registering meta info for page is optional for plugin development, also it can be registered manually in admin panel under "admin/meta/add" link. However if you require to register meta(s) during plugin installation below code is an example of registering meta inside index() function.

 //// META INFO ////

$meta[]=array(

"title"=>"Page Title Example",

"language_id"=>language_id(),

"class_routes"=>"/controller",

"link"=>"page-title-example.html",

"type"=>"1",

);

foreach($meta as $m){

if(! $this->meta_model->meta($m)->num_rows ){

$this->db->insert("meta",$m);

$meta_id=$this->db->insert_id();

if( $m["type"]==1){

$this->db->where("meta_id",$meta_id)->update("meta",array("m_id"=>$meta_id));

}

}else{

/// already exist do nothing

}

//// META INFO ////

 

 

Plugin related mysql table(s) (optional)


Plugin related mysql table is creation of table that plugin use for data,  usually using create table sql code query. Below an example of database qurey creating a mysql database table inside index() function.

/// CREATE TABLE  FOR PLUGIN ///

$this->db->query("

CREATE TABLE IF NOT EXISTS `example_category` (

  `example_category_id` int(11) NOT NULL AUTO_INCREMENT,

  `title` varchar(255) CHARACTER SET utf8 DEFAULT NULL,

  `slug` varchar(255) CHARACTER SET utf8 DEFAULT NULL,

  `status` int(11) DEFAULT '1',

  `sort_order` int(11) DEFAULT '10',

  `keywords` varchar(255) DEFAULT NULL,

  `description` varchar(255) DEFAULT NULL,

  PRIMARY KEY (`example_category_id`)

) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

");

/// CREATE TABLE  FOR PLUGIN ///

 

 



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




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