Note: This post expects the reader to be a Joomla developer. If you’re a casual Joomla user with no programming experience then most likely this post is not for you.
Sometimes, you search the web for a solution to something in Joomla and all you find is:
- Outdated information
- Code that doesn’t work
- Code that only works under certain conditions
- Complicated code
The above is the case of many Joomla developers trying to get the global parameters of the current component (just try to make a search on Google, and you’ll see that the results returned mostly consist of: 1) code for Joomla 1.5, 2) spaghetti code, 3) code that may or may not work, 4) etc…).
Thankfully, there’s always itoctopus to the rescue!
If you want to get the global parameters of a component in Joomla 2.5 then all you need to do is use the following code:
$app = JFactory::getApplication(); $params = $app->getParams();
That’s it – the global parameters are inside the $params array! Yes – it’s that simple – but unfortunately, very rare are those who know of this solution.
What’s interesting about the above code is that it works anywhere: in your model/view/controller if you’re using MVC to develop your component, in your template files, and anywhere else! We have tested it!
But how come the above code works anywhere?
As a rule of thumb, any method on the JSite object type (which is the object type returned by the JFactory::getApplication(); method) can work anywhere on your website. This is because the JSite object is available on every page on the frontend of your Joomla website.
We don’t usually write short posts – but this post was necessary to ensure Joomla developers retrieve the current component parameters the right way (e.g. the way that those who developed Joomla wanted us to do it). If the above code doesn’t work for you (very unlikely) or if you need further help, then please contact us. We are experts in Joomla, we work very hard, we deliver on time, and our fees are super reasonable!