2

In my Joomla application, I have functionality where I use server variables, like request_uri and query parameters for parsing url string.

This function is used in many modules. So, I wanted to implement the same functionality by using a custom plugin, following Joomla tutorial.

My question is whether using a plugin in this case is appropriate.
And can we use server objects in a plugin class?

If yes, how to use this plugin in my other modules and components.

Any detailed answers are appreciated.

1
  • Can you provide a bit more detail regarding how your modules will use the gathered information? Also, if you're simply grabbing URL query parameters there's a much, much, much simpler way using Joomla core. Commented May 17, 2016 at 15:28

1 Answer 1

3

You could create your own library with the functionality you want to re-use in all your extensions and load it each time with JLoader.

The $_SERVER is a SUPERGLOBAL variable and can be accessed anytime from everywhere.

Since you are working with Joomla, you may want to use what Joomla has to offer, so have a look at JURI

Job could be done with a plugin as well. For example you could create a system plugin and in your plugin's classes create public methods.

Accessing your plugin from your modules:

$myPluginFramework = new MyPluginFramework();

$myPluginFramework->myRequestUri();

Note that the plugin must be enabled in order to be able to create a new object of your plugin class. You probably have to consider any checks for if the class exists

if (class_exists('MyPluginFramework')) {
    $myPluginFramework = new MyPluginFramework();
    $myPluginFramework->myRequestUri();
    ...
}
2
  • Is it necessarily be a system plugin? Or can i use a content plugin with an event like on content prepare
    – user168983
    Commented May 17, 2016 at 20:23
  • @user168983: I don't see how the onContentPrepare would be useful in your case, and generally a system plugin sounds a better fit in the context of your needs. Again, I think it could be better if you simply create your own lib (framework) and use it in your extensions as and when needed.
    – FFrewin
    Commented May 18, 2016 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.