【问题标题】:Create new module in Magento2 stable version?在 Magento2 稳定版中创建新模块?
【发布时间】:2015-11-18 09:38:36
【问题描述】:

随着 Magento2 稳定版发布,我们应该如何创建新模块?在 Magento2 稳定版中创建新模块所需的确切步骤是什么?有什么方法可以将 Magento2 Beta 模块转换为稳定版模块?

期待听到您的想法。

【问题讨论】:

    标签: magento2


    【解决方案1】:

    我终于找到了在稳定版 Magento2 中创建新模块的成功方法:

    以下是创建新模块所需的文件列表,我的包名称是 Ktpl,模块名称是 Brandmanager

    1) 在 app/code/Ktpl/Brandmanager/etc/module.xml 中创建 module.xml

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
        <module name="Ktpl_Brandmanager" setup_version="2.0.0">
        </module>
    </config>
    

    2) 在 app/code/Ktpl/Brandmanager/composer.json 中创建 composer.json

    {
      "name": "ktpl/brandmanager",
      "description": "Brand manager adds the facility to manage store brands in Magento2",
      "require": {
        "php": "~5.5.0|~5.6.0|~7.0.0",
        "magento/module-store": "*",
        "magento/module-backend": "*",
        "magento/framework": "*"
      },
      "type": "magento2-module",
      "license": "GPL-3.0",
      "authors": [
        {
          "name": "KTPL",
          "email": "chirag.bhavsar@krishtechnolabs.com"
        }
      ],
      "autoload": {
        "files": [
          "registration.php"
        ],
        "psr-4": {
          "Ktpl\\Brandmanager\\": ""
        }
      }
    }
    

    3) 在app/code/Ktpl/Brandmanager/registration.php 处创建registration.php 文件

    <?php
    
    \Magento\Framework\Component\ComponentRegistrar::register(
        \Magento\Framework\Component\ComponentRegistrar::MODULE,
        'Ktpl_Brandmanager',
        __DIR__
    );
    

    放置这些文件后,从 Magento 根目录运行以下命令。

    sudo php -f bin/magento setup:upgrade
    sudo rm -rf var/cache/*
    sudo rm -rf var/page_cache/*
    sudo rm -rf var/generation/*
    

    此过程将成功注册您的模块,您将能够在商店 -> 配置 -> 高级 -> 高级部分看到您的模块。

    【讨论】:

    • 感谢您的回答。 Beta 版和稳定版之间的 Developer Doc 示例中肯定存在不一致。这对我有很大帮助。
    • 很高兴听到它对您有所帮助。
    【解决方案2】:

    我不会给你一步一步的指导,这里不适合这样的答案。

    最近最显着的变化是在模块路由中需要registration.php和composer.json

    例如。

    https://github.com/magento/magento2/blob/develop/app/code/Magento/AdminNotification/composer.json

    https://github.com/magento/magento2/blob/develop/app/code/Magento/AdminNotification/registration.php

    我只想为你的新模块添加核心,这是最简单的方法。

    【讨论】:

    猜你喜欢
    • 2016-10-03
    • 2015-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-21
    • 1970-01-01
    • 2017-04-10
    相关资源
    最近更新 更多