data-id="1190000005008433" data-license="cc">
1、在app/etc/config.php中添加自訂的模組(magento1聲明模組是在app/etc/modules):
'Silk_Helloworld' =>1,
值為1,開啟模組,類似true,0關閉模組
2、建立module.xml:app/code/Silk/Helloworld/etc/module.xml
3、建立前段控制器:app/code/Silk/Helloworld/ect/fronted/routers.xml
4、建立一個控制器:appcodeSilkhelloworldControllerIndexindex.php
namespace Silk\Helloworld\Controller\Index;class Index extends \Magento\Framework\App\Action\Action{ public function execute() { $this->getResponse()->appendBody('HELLO WORLD'); }}
5、建立檔案app/code/Silk/Helloworld/registration.php:
\Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Silk_Helloworld',/*namespace/module*/ __DIR__);
6、建立檔案app/code/Silk/Helloworld/composer.json:
{
"name": "silk/helloworld",/*namespace/module*/ "description": "silk",/*namespace*/ "require": { "php": "~5.5.0|~5.6.0|~7.0.0", "magento/framework": "100.0.*", "magento/module-ui": "100.0.*", "magento/module-config": "100.0.*", "magento/module-contact": "100.0.*" }, "type": "magento2-module", "version": "100.0.0", "license": [ "OSL-3.0", "AFL-3.0" ], "extra": { "map": [ [ "*", "Silk/Hellworld"/*namespace/module*/ ] ] }, "autoload": { "files": [ "registration.php" ], "psr-4": { "silk\\helloworld\\": ""/*namespace/module*/ } }}
7、執行命令:php bin/magento setup:upgrade
xampp環境使用該命令方法:
(1)、開啟shell,輸入cd htdocsmagento,斷行符號
(2)、輸入上面的命令,等待一會即可.
linux環境:
php bin/magento setup:upgrade
8、在瀏覽器中輸入silk.magento2.cn/helloworld.顯示:
helloworld模組建立成功了。
9、登入到後台,可以查看建立的helloworld模組: Stores > Configuration > Advanced > Advanced.
以上就介紹了magento 2模組開發執行個體helloworld模組,包括了helloworld,magento方面的內容,希望對PHP教程有興趣的朋友有所協助。