Example 1 : How to Create Magento2 Hello World Example
or
Example 1 : How to Create Custom Extension in Magento2 ?
Please Follow My Steps for this.
1. Please install Magento2 in your Localhost and. Create folder as mention below.
We have to create "code/MSG/HelloWorld" folder inside app folder in root directory.
"app/code/MSG/HelloWorld"
2. We have to create "module.xml" file in etc folder.In Magento2 "module.xml" is required
File to Create Custom Extension.
"app/code/MSG/HelloWorld/etc/module.xml"
3. We have to create "registration.php" file in etc folder.In Magento2 "registration.php" is required File to Create Custom Extension.
"app/code/MSG/HelloWorld/registration.php"
In Magento2 to Register Extenstion in We are using "ComponentRegistrar" class.
We are using "register" method of it.
1. First argument of register method is for "MODULE" register or register Extension
"MSG_HelloWorld" to the Magento.
2. Second argument is Extension name "MSG_HelloWorld"
We can set Extension name by :
1. MSG is Folder name in app.
2. HelloWorld is Folder name in app.
3. Run Setup Upgrade Command in Console.
php bin/magento setup:upgrade
How to check Magento2 Extension is Installed or Active.
Two ways to check
1. We can see "MSG_HelloWorld" Extension in this location "app/etc/config.php"
2. We can run Command in Console to Check Extension is "Enable/Disable"
php bin/magento module:status
How to "Enable/Disable" Custom Extenstion in Magento2 ?
1. We can run Command in Console for "Enable" Custom Extenstion in Magento2
php bin/magento module:enable MSG_HelloWorld
2. We can run Command in Console for "Disable" Custom Extenstion in Magento2
php bin/magento module:disable MSG_HelloWorld
4. Create "route.xml" file
"app/code/MSG/HelloWorld/etc/frontend/routes.xml"
5. Create Controller
"app/code/MSG/HelloWorld/Controller/Index/Test.php"
We can run Command in Console for clear cache.
php bin/magento cache:clean
Now Please run below URL in Browser
http://localhost/projectname/helloworld/index/test