There are times when you want to determine your module’s version number programmatically — I like to append module versions to the User-Agent header of any calls back to my web services so I can access current statistics about version usage. Now, you could just include a constant somewhere in your module and update it as necessary. But why do that when the Mage core already has access to the value you defined in your config.xml file?

Here’s a simple example, assuming your module is called Myapp and is in the Package code namespace:

$version = Mage::getConfig()->getModuleConfig("Package_Myapp")->version;

This is fairly straight forward. The Mage::getConfig() method gets a reference to the config parsing class, and then we can load up the config specific to our module using the getModuleConfig method. We actually have access to a few more variables beyond version, depending on the structure of your config file, but version seems to be the most useful.

Share this article:

If this resonates with you I'd love to help!

I help business with problems like these every day.

Click below to schedule a call.

About The Author

Bryce Hamrick

Facebook Twitter

Bryce Hamrick is an entrepreneur, business & marketing strategist, and product consultant with nearly two decades of experience in industry. Bryce has been a software engineer, product manager, and director of product management for startups as well as large enterprises. He has led teams to bring dozens of products to market and has executed numerous six-figure product launches. Today Bryce and his team focus on leveraging his product execution strategy to help businesses with growth and scale.