Programmatically: How to create custom Magento modules
Step 1: Create a new folder for your module
Create a new folder in the app/code/local directory (or app/code/community if you want to share your module with the community) with the name of your module. For example, MyCompany_MyModule.
Step 2: Create the module declaration file
Inside the MyCompany_MyModule folder, create a new file named etc/module.xml. This file will declare your module and its dependencies. Here's an example:
1.0.0
Step 3: Create the module configuration file
Create a new file named etc/config.xml inside the MyCompany_MyModule folder. This file will contain configuration settings for your module. Here's an example:
?xml version="1.0"?>
MyCompany_MyModule
Step 4: Create the controller
Create a new folder named controllers inside the MyCompany_MyModule folder and create a new PHP file named MyController.php. This file will contain the logic for your controller.
class MyCompany_MyModule_Controller_MyController extends Mage_Core_Controller_Varien_Action
{
public function indexAction()
{
// Your controller logic goes here
echo 'Hello World!';
}
}
Step 5: Create the layout XML
Create a new file named layout/MyCompany_MyModule.xml inside the MyCompany_MyModule folder. This file will define the layout for your module.
?xml version="1.0"?>
mytemplate.phtml
Step 6: Create the block
Create a new folder named Block inside the MyCompany_MyModule folder and create a new PHP file named MyBlock.php. This file will contain the logic for your block.
class MyCompany_MyModule_Block_MyBlock extends Mage_Core_Block_Template
{
public function _prepareLayout()
{
// Your block logic goes here
}
}
Step 7: Create the template
Create a new folder named frontend inside the MyCompany_MyModule folder and create a new PHP file named mytemplate.phtml. This file will contain the HTML template for your block.
Hello World!
To use your module, go to System > Configuration > Advanced > Disable Modules Output and select "Yes" next to "Disable Module Output". Then, go to System > Cache Management and refresh the cache.
You can now access your module by going to [your-magento-site]/mycontroller/index.
This is just a basic example, but you can extend and customize your module as needed to fit your specific requirements.
true
local
This will enable your module in Magento.