Magento: Mage:: Static Functions
I’m sure if you are a Magento developer, you’ve seen or used a lot of these types of methods: Mage::app(), Mage::getModel(), Mage::getSingleton(), etc. I’d like to explain how and why these work if you are unaware.
First, if you open up app/Mage.php, you’ll notice that the class declaration is final class Mage
. The ‘final’ php keyword prevents this class from being overridden (extended). Second, you’ll notice that every function in the class is a static function, for instance: public static function getVersion()
. A static function basically means that you do not need to instantiate the class/object to use the method.
I will list out some of the main, most useful methods available here. If you want to see the others, just open up app/Mage.php and have a look. You can call these anywhere within your application:
Mage::getVersion()
Mage::getModel($modelClass = '', $arguments = array())
Mage::helper($name)
Mage::log($message, $level = null, $file = '', $forceLog = false)
Mage::app()
Mage::getStoreConfig($path, $store = null)
Mage::getBaseUrl($type = Mage_Core_Model_Store::URL_TYPE_LINK, $secure = null)
Mage::register($key, $value)
Mage::unregister($key)
Mage::registry($key)
Mage::getBaseDir($type = 'base')
Mage::getModuleDir($type, $moduleName)
Mage::getStoreConfigFlag($path, $store = null)
Mage::getConfig()
Mage::getUrl($route = '', $params = array())
Mage::getDesign()
Mage::dispatchEvent($name, array $data = array())
Mage::getSingleton($modelClass = '', $arguments = array())
Mage::getResourceModel($modelClass, $arguments = array())
Mage::throwException($message, $messageStorage = null)
Mage::setIsDeveloperMode($mode)
Mage::getIsDeveloperMode()