How to create your own plugin in joomla

to create your own plugin in joomla bascically you need two file s one is installation file(i.e. xml file) and other one is php file. you can zip both file and install it with joomla bcs joomla allow zip installation. example shows testing.XML installation file for the testing plugin. where testing is your plugin name.

testing sanjay may 2009 (C) 2009 Open Source Matters. All rights reserved.
GNU/GPL a1p_tony@yahoo.com http://indiapoly.com 1.1 this is a testing plugin

//below we call the php file that store the plugin code

// testing.php


// e.g. of parameters currently i used a search parameters as example


//
Creating the Plugin or testing.php file
extends JPlugin {


/** * Constructor * * For php4 compatability we must not use the __constructor as a constructor for * plugins because func_get_args ( void )


returns a copy of all passed arguments * NOT references. This causes problems with cross-referencing necessary for the * observer design pattern. */


function plg
( &$subject ) {


parent::__construct( $subject ); // load plugin parameters $this->_plugin = > JPluginHelper::getPlugin( '', '
' ); $this->_params = new JParameter( $this->_plugin->params );



}



/** * Plugin method with the same name as the event will be called automatically. */



function () {



global $mainframe; // Plugin code goes here. return true; }



}



Using Plugins in Your Code Now that you’ve created your plugin, now you need to call it in your code. the Joomla! core has a number of built-in events that you might want your plugin code to be registered to. In which case you don’t need to do the following. If you want to trigger an event then you use code like this:

$results = $mainframe->triggerEvent( '',
);


It is important to note that the parameters have to be in an array. The plugin function itself will get the parameters as single values. The return value will consist of an array of return values from the different plugins (so it can also contain multilevel arrays).