当前位置: 代码迷 >> Web前端 >> Magento: Mage: Static Functions
  详细解决方案

Magento: Mage: Static Functions

热度:972   发布时间:2012-09-06 10:37:01.0
Magento: Mage:: Static Functions

Magento: Mage:: Static Functions

<!-- .entry-meta -->

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()
    ????Returns your current Magento version.
    ?
  • Mage::getModel($modelClass = '', $arguments = array())
    ????Returns a new model object.
    ?
  • Mage::helper($name)
    ????Returns a helper object.
    ?
  • Mage::log($message, $level = null, $file = '', $forceLog = false)
    ????Logging tool. If you only pass in a message, it logs to var/log/system.log, if you have logging enabled.
    ?
  • Mage::app()
    ????Initialize a Magento application object.
    ?
  • Mage::getStoreConfig($path, $store = null)
    ????Returns config value by path (basically anything in System >> Configuration).
    ?
  • Mage::getBaseUrl($type = Mage_Core_Model_Store::URL_TYPE_LINK, $secure = null)
    ????Returns the base URL by type.
    ?
  • Mage::register($key, $value)
    ????Registers a new variable in the registry.
    ?
  • Mage::unregister($key)
    ????Unregisters a variable in the registry.
    ?
  • Mage::registry($key)
    ????Returns a value from the registry by the given key.
    ?
  • Mage::getBaseDir($type = 'base')
    ????Returns the root absolute path. You can of course change which website by passing in the code.
    ?
  • Mage::getModuleDir($type, $moduleName)
    ????Returns the absolute path of a given module.
    ?
  • Mage::getStoreConfigFlag($path, $store = null)
    ????Returns a config flag by path.
    ?
  • Mage::getConfig()
    ????Returns a config instance.
    ?
  • Mage::getUrl($route = '', $params = array())
    ????Generates a url by route and parameters.
    ?
  • Mage::getDesign()
    ????Returns a design package singleton.
    ?
  • Mage::dispatchEvent($name, array $data = array())
    ????Dispatches an event in Magento.
    ?
  • Mage::getSingleton($modelClass = '', $arguments = array())
    ????Returns a model object singleton.
    ?
  • Mage::getResourceModel($modelClass, $arguments = array())
    ????Returns a resource model object.
    ?
  • Mage::throwException($message, $messageStorage = null)
    ????Throw an exception, the Magento way.
    ?
  • Mage::setIsDeveloperMode($mode)
    ????Turns developer mode on or off ($mode should be true or false).
    ?
  • Mage::getIsDeveloperMode()
    ????Returns if developer mode is enabled or not
  相关解决方案