`
andyyang007
  • 浏览: 21342 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

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
分享到:
评论

相关推荐

    Magento: 后台添加预览按钮 View product in frontend from Magento admin

    这篇博客“Magento:后台添加预览按钮 View product in frontend from Magento admin”主要探讨了如何通过自定义开发来实现这一功能,让管理员能够快速检查商品在网站前台的显示状态。 在Magento中,通常管理员需要...

    Magento: Beginner's Guide ([Packt]出品 Magento新手指南)

    ### Magento新手指南知识点详解 #### 一、Magento简介与特性 **Magento**是一款功能强大的开源电子商务平台,由Varien公司(后被Adobe收购)于2008年首次发布。它以其灵活性、可扩展性和丰富的功能集而闻名,是...

    module-requirejs::mage:Magento 2模块演示了RequireJS的用法

    RequireJS Magento 2模块Magento 2模块演示了RequireJS的用法。内容设置将模块放在app/code/Koz/RequireJS ,或通过Composer安装。 $ composer config repositories.koz-requirejs vcs ...

    Magento:适用于Dropday的Magento扩展

    通过SFTP或SSH导航到Magento [Magento]/app/code/ 。 上载带有扩展名的Dropday/OrderAutomation目录。 打开终端并导航到Magento根目录。 运行以下命令以启用Dropday扩展: php bin/magento module:enable Dropday_...

    magento2-integration

    Magento:registered:2数据集成借助Datatric Connect扩展程序,可以轻松地将Magento:registered:2商店与Datatrics平台连接起来。安装在开始安装过程之前,我们建议您对webshop文件以及数据库进行备份。 有两种安装...

    The Definitive Guide to Magento (Apress出品 Magento权威指南)

    ### Magento权威指南 #### 书籍概述 《Magento权威指南》是由Adam McCombs与Robert Banh共同编著的一本深入探讨Magento电商平台的技术手册。该书由Apress出版社于2009年出版发行,旨在为读者提供一个全面、系统的...

    docker-magento:Mark Shust的Magento Docker配置

    docker-magento:Mark Shust的Magento Docker配置

    magento:Magento片段

    3. **模板语法**:熟悉PHTML文件中的Mage::helper()、Mage::getUrl()等函数,以及{{block}}和{{template}}指令。 4. **变量传递**:了解如何在控制器、Block和模板之间传递数据,如使用`setData()`和`getData()`方法...

    magento:megento电子商务网站

    magento:megento电子商务网站

    ansible-magento:ansible置备的magento商店

    ansible-magento要求: -流浪汉-可以指示: 克隆此仓库无所事事在浏览器中导航到magento.dev。MySQL 数据库:magento 用户名:magento 密码:password123 这是基于的工作而进行的一些更改,以简化启动和运行过程...

    m2_belvg_product-tabs-2.0.0.zip

    4. Recompile static files: php bin/magento setup:static-content:deploy 5. Flush cache php bin/magento cache:flush,...To activate the module log into the Magento admin panel and navigate to Stores -&gt; ...

    bolt-magento2:magento2的Bolt插件

    插件安装打开命令提示符,转到&lt;MAGENTO&gt;文件夹并运行以下命令: $ composer require boltpay/bolt-magento2$ php bin/magento setup:upgrade$ php bin/magento setup:di:compile$ php bin/magento setup:static-...

    magento:Magento的免费PWA和SPA

    VueFrontCMS Connect App for Magento 显示你的 :red_heart: -给我们一个 :star: 帮助我们将这个项目发展到最好! VueFront是CMS不可知的SPA和PWA前端,适用于您的老式Blog和电子商务网站。 Magento通过最佳的电子...

    流浪者-magento:**已弃用**

    流浪者-magento:**已弃用**

    edge-docker-magento:Magento在Docker上运行

    边缘docker-magento Magento在Docker上运行。 与Gitpod和Eclipse Che搭配很好。 专为开发使用而设计。 定期更新以最新的2. *版本(请参阅分支)。 配置选项 大多数配置都可以使用环境变量来完成。 以下是可用的...

    magento:Puglin Magento

    $ cd /path/to/magento $ modgit init $ modgit add epicomtech_magento https://github.com/epicomtech/magento.git Antes deComeçar Epicom的API协议 通过电子邮件联系API,电子邮件地址: Conhecendo omó...

    magento:Magento 2

    Magento 2 是一款开源的电子商务平台,用于构建和管理在线商店。它由Adobe公司拥有,是Magento 1的升级版本,提供了许多改进的功能和性能优化。Magento 2 的设计目标是提供一个高度可定制、功能丰富的电商解决方案,...

    laravel-magento:用于访问Laravel中本地安装的Magento类的软件包

    用法初始化Mage类,然后可以像在Magento框架中一样使用它。 法师:: init('admin','store');表现您可以使用特定的模块初始化该类,以提高性能。 法师:: init('admin','store',array(),Config :: get...

    magento:magento 项目

    马恩托 magento 项目

    magento:magento-ce 2.4.0

    以下是一些关于 Magento CE 2.4.0 的核心知识点: 1. **增强的安全特性**: - Magento 2.4.0 强化了安全防护,包括对 SQL 注入、XSS 攻击的防御,以及增强了密码策略和支付网关的加密。 - 集成了 PCI DSS...

Global site tag (gtag.js) - Google Analytics