Do you want to create a new page in Magento ? or Do you want to create a new module in Magento ? If yes, Then ok, just spend 10 minutes and follow below steps.
Objectives: I will create a new page in Magento whose output will be “Hello World ! I am a Magento Guy..”.
Target: Create a new module called “HelloWorld”
Step 1: Module Declaration
Create app/etc/modules/M4U_HelloWorld.xml and write below code
<?xml version="1.0"?> <config> <modules> <M4U_HelloWorld> <active>true</active> <codePool>local</codePool> </M4U_HelloWorld> </modules> </config>
Step 2: Module Configuration
a. Create a controller class app/code/local/M4U/HelloWorld/controllers/IndexController.php
class M4U_HelloWorld_IndexController extends Mage_Core_Controller_Front_Action { public function indexAction() { $this->loadLayout(array('default')); $this->renderLayout(); } }
b. Create a Block class app/code/local/M4U/HelloWorld/Block/HelloWorld.php
class M4U_HelloWorld_Block_HelloWorld extends Mage_Core_Block_Template { // necessary methods }
c. create configuration xml in app/code/local/M4U/HelloWorld/etc/config.xml
<?xml version="1.0"?> <config> <global> <modules> <m4u_helloworld> <version>0.1.0</version> </m4u_helloworld> </modules> <blocks> <helloworld> <rewrite> <helloworld>M4U_HelloWorld_Block_HelloWorld</helloworld> </rewrite> </helloworld> </blocks> </global> <frontend> <routers> <helloworld> <use>standard</use> <args> <module>M4U_HelloWorld</module> <frontName>helloworld</frontName> </args> </helloworld> </routers> <layout> <updates> <helloworld> <file>helloworld.xml</file> </helloworld> </updates> </layout> </frontend> </config>
Define Frontend Template :
1. Define page layout in app/design/frontend/M4U/default/layout/helloworld.xml
N.B: Use default instead of M4U as template location if you use default design packages. Means create file in app/design/frontend/default/default/layout/helloworld.xml
<?xml version="1.0"?> <layout version="0.1.0"> <helloworld_index_index> <reference name="root"> <action method="setTemplate"><template>page/1column.phtml</template></action> </reference> <reference name="content"> <block type="helloworld/helloworld" name="hello" template="helloworld/helloworld.phtml"/> </reference> </helloworld_index_index> </layout>
2. Create template file app/design/frontend/M4U/default/template/helloworld/helloworld.phtml and write down
N.B: Use default instead of M4U as template location if you use default design packages. Means create file in app/design/frontend/default/default/template/helloworld/helloworld.phtml
Hello World ! I am a Magento Guy..
Hey, new module is ready to run and hit browser with url http://127.0.0.1/projectname/index.php/helloworld/
(关闭缓存或者刷新缓存)
and see result.
That’s it……..
Is it easy or not ? what you think ?
Coder, Please at first try yourself.
Ohh.., Still are you facing problem ? Lets download full module source code from left panel “BOX” section or let me know.
Note: I have upgraded HelloWorld module source code of BOX widget. So it will resolve the problem which was faced by some guys.
原文:http://magento4u.wordpress.com/2009/06/08/create-new-module-helloworld-in-magento/
参考:http://www.hellokeykey.com/magento-module-tutorial-1-hello-world/
相关推荐
Magento最简单的二次开发Helloworld源代码
Helloworld with Custom System Config 其他与Magento开发相关的文章 简单的EAV数据查询 清除缓存的几种方法 通过命令行来升级Magento MAGENTO数据转移 如何使用和设置Cookie&Session Magento中我的账户访问...
Chapter 1, Installing Magento 2 on Apache and NGINX, is a...new methods introduced in the Magento 2 framework and examples on how to create basic functions. Chapter 8, Creating Magento 2 Extensions – Ad
new methods introduced in the Magento 2 framework and examples on how to create basic functions. Chapter 8, Creating Magento 2 Extensions – Advanced, explains how to use advanced features in ...
Magento 2 Beginners Guide by Gabriel Guarino English | 14 Mar. 2017 | ASIN: B01MS81BQX | 442 Pages | AZW3 | 31....He is also a moderator in Magento forums, and he is a frequent speaker at Magento events.
将图片上传器添加到Magento后端在后端上传的图像可以在前端int的相应页面中查看易于在任何magento安装中使用安装✓通过作曲家安装在Magento 2根文件夹中运行以下命令: composer require prateekkarki/module-...
对于首次安装magento过程中出现的问题的小结
magento首页展示用户设置的新产品模块列表
magento2-blog-module-tutorial, 关于如何从头开始创建 magento 2模块的教程,带有测试 2博客模块教程这个模块是 WIP,它将被更新为每个教程我目前正在写。介绍如何从头创建完整功能的Magento 2模块。 即使有测试,...
如何在Magento创建一个简单的“Hello World”模块?
NULL 博文链接:https://justcoding.iteye.com/blog/1725217
NULL 博文链接:https://justcoding.iteye.com/blog/1886183
NULL 博文链接:https://justcoding.iteye.com/blog/1711166
magento数据结构分析 magento数据字典
安装composer require swissup/module-codemirrorbin/magento setup:upgrade用法UI组件例子: <? xml version = " 1.0 " encoding = " UTF-8 " ?>< form xmlns : xsi = " ...
magento2在产品详情添加自定义tab,1. Enable module with php bin/magento module:enable BelVG_ProductTabs 2. Run php bin/magento setup:upgrade 3. Recompile DI php bin/magento setup:di:compile 4. Recompile...
从入门开始讲解magento的框架结构,然后教你开发一个简单的hello world模块接着是讲解magento中的mvc和zend的区别,最后讲到了magneto的高级资源模型.
它用于Magefan的和要求Magento社区版2.0.x-2.4.x或Magento企业版2.0.x-2.4.x安装方法1-通过composer安装打开命令行使用命令“ cd”导航到您的magento2根目录运行命令:作曲家需要magefan / module-geoip composer ...