Hello everyone, we will explain how to create an instance of a Joomla plugin, in this case has served us well for joomla joomla 1.5 to 1.7 for the same. Imagine if we have a plugin that takes care of obtaining data from a table Y X, and we need that information to mount a component, or to use such data in a module. If you already have a joomla plugin that makes us function and Z, how to reinvent the wheel?. Let’s use this. The first step is to instantiate the plugin. This is indicated with the following call:

&JPluginHelper::importPlugin("[tipoPlugin]", "[nombredelPlugin]");

This brings us back an instance of the plugin Z [nombredelPlugin], so we must give this statement to a variable created by us. importPlugin is a static method of class libraries JPluginHelper within joomla, so that we can instantiate it from anywhere in our code indicating that we call a static method <::> Once we have the instance need a “trigger”. A trigger in joomla is a class object that handles JDispatcher send the call to a method. In Joomla Singleton pattern is used for creating delpor what we should not create a new one, but instantiate this:

JDispatcher::getInstance();

With this we ensure that we give the same object that already existed and not duplicate information created, as in the previous case this call is to a static method of the class and we will return JDispatcher an object of that type, we must assign a variable to store the object returned. This object we need yes or yes because it is who is going to take to make the call to the function Z of our plugin. As a last step we have to send the call to the appropriate estimos event, we can treat event as “method” but only in this example to make (an event is not the same as a method, EYE). To launch an event object that we use the previously obtained with JDispatcher calling the method
JDispatcher class. example:

$dispatcher->trigger( '[nombredelEvento]', array( )[array de parametros para el metodo del plugin]);

This method requires as arguments:

The name of the event to launch, which corresponds to the name of the method that contains the plugin which we have previously instantiated
Waiting list of parameters that method, we parasarlos as array in the call to trigger
Depending on what happens in this function the plugin will return a value, or show one outcome or another action that has this developed for this case.

There are some plugin that do not implement the class-structure methods, so that when we make the call to the trigger method if we look at [nombredelEvento]‘re having an event that is registered as an event in the plugin, this can be seen searching for the plugin we are going to instantiate; Within this in your. php can see if it contains calls and events registerEvent records, if not registered as an event the method to which we can instantiate a new event record us. If the plugin that instantiate the event has not launched as recorded, nor a class with a method that is called as such we call the method, this process will fail null results obtained in the process.