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.
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.