magento 2模組開發執行個體helloworld模組 hello world 程式 c語言hello world代碼 c語言hello worl

來源:互聯網
上載者:User
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教程有興趣的朋友有所協助。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.