Do you want to create a new page in Magento

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.
Target: Create a new module called “HelloWorld”
Step 1: Module Declaration
Create app/etc/modules/Tatva_HelloWorld.xml and write below code
1
2
3
4
5 true
6 local
7
8
9
Step 2: Module Configuration
a. Create a controller class app/code/local/Tatva/HelloWorld/controllers/IndexController.php
1 class Tatva_HelloWorld_IndexController extends Mage_Core_Controller_Front_Action
2 {
3 public function indexAction()
4 {
5 $this->loadLayout(array(’default’));
6 $this->renderLayout();
7 }
8 }
b. Create a Block class app/code/local/Tatva/HelloWorld/Block/HelloWorld.php
1 class Tatva_HelloWorld_Block_HelloWorld extends Mage_Core_Block_Template
2 {
3 // necessary methods
4 }
c. create configuration xml in app/code/local/Tatva/HelloWorld/etc/config.xml
01
02
03
04
05
06 0.1.0
07
08
09
10
11
12 Tatva_HelloWorld_Block_HelloWorld
13
14
15
16
17
18
19
20
21 standard
22
23 Tatva_HelloWorld
24 helloworld
25
26
27
28
29
30
31 helloworld.xml
32
33
34
35
36
Define Frontend Template :
1. Define page layout in app/design/frontend/Tatva/default/layout/helloworld.xml
N.B: Use default instead of Tatva as template location if you use default design packages. Means create file in app/design/frontend/default/default/layout/helloworld.xml
01
02
03
04
05
06
07 page/1column.phtml
08
09
10
11
12
13
14
2. Create template file app/design/frontend/Tatva/default/template/helloworld/helloworld.phtml and write down
N.B: Use default instead of Tatva 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
Creating a New Magento Module
Magento is a built on top of the Zend Framework. The Zend Framework supports modularizing your application, and Magento went the way of the module as part of it’s core design. In this short article, I will explain how to create a new module manually, and how to use the Module Creator to help you create modules quickly.
To create a “bare bones” module in Magento you should create your folder in the local code pool. There are generally two parts to naming the module. 1.) The namespace 2.) The module name.
The namespace is a folder used to group modules together, generally representing the company that developed the module. In this example, the namespace is “Super”. The name of our module is “Awesome”. So, I will create the following folder structure: base_magento_dir/app/code/local/Super/Awesome.
Next I will do the only real required part of a module; create the module’s xml file. If you look in the base_magento_dir/app/etc/modules directory, you will find all of the .xml files that define the Magento core modules. We will create an .xml file in here for our module called: Super_Awesome.xml:
?
1
2
3
4
5
6
7
8
9

true
local

Additionally, if we know that our module depends on other modules to function, we can declare those dependencies. In our example, Super_Awesome depends on Mage_Core and Mage_Catalog:
?
1
2
3
4
5
6
7
8
9
10
11
12
13

true
local

After you dump your cache, you now have an installed module that does absolutely NOTHING . Generally, you will have a folder structure that looks something like this:
Super
|_ Awesome
|_Block
|_controllers
|_etc
|_Helper
|_Model
|_sql
The folders are pretty self explanatory minus the etc. The “etc” directory generally contains config files; the most common being config.xml. Below is a typical sample of the beginnings of a config file.
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

0.1.0

standard

Super_Awesome
awesome

awesome.xml

Super_Awesome_Model
awesome_mysql4

Super_Awesome_Model_Mysql4

Super_Awesome

core_setup

core_write

core_read

Super_Awesome_Block

Super_Awesome_Helper

Now you are on your way to making your first billion dollar extension! Woo-hoo!
The Module Creator is a Magento “Extension” that allows you to fill in a few questions (Module Name, Namespace, Magento Root Dir, and some Design questions), and then will auto-generate all the files necessary to get you started on your module. The coolest thing about the Module Creator is the way you can create templates/skeletons/frameworks of modules and store them for later use. For instance, if you are in the business of creating Payment modules, you can create a skeleton with all of the common classes and configs, and then use that skeleton to jump start all of your Payment module development. Module Creator is generally a time saver and recommended for a noobs.

Gửi phản hồi

Please log in using one of these methods to post your comment:

WordPress.com Logo

Bạn đang bình luận bằng tài khoản WordPress.com Log Out / Thay đổi )

Twitter picture

Bạn đang bình luận bằng tài khoản Twitter Log Out / Thay đổi )

Facebook photo

Bạn đang bình luận bằng tài khoản Facebook Log Out / Thay đổi )

Google+ photo

Bạn đang bình luận bằng tài khoản Google+ Log Out / Thay đổi )

Connecting to %s

%d bloggers like this: