Warning: Cannot modify header information - headers already sent by (output started at /www/wwwroot/sbboke.com/wp-content/plugins/wordpress-seo/src/integrations/front-end-integration.php:409) in /www/wwwroot/sbboke.com/wp-content/themes/pacify/content-single.php on line 5

如何在Magento 2中打包模块?

如何在Magento 2中打包模块composer.json在实现任何模块的包装之前,将通过创建一个 composer 文件来指导您完成本主题。借助composer文件,可以在应用程序实例中交付,安装和升级组件。

包装模块概述在Magento 2中

  • 步骤1:设置Magento Composer文件(composer.json
  • 步骤2:使用来注册组件 registration.php
  • 步骤3:打包并生成组件
  • 步骤4:查看示例composer.json

步骤1:设置Magento Composer文件(composer.json

composer.json文件允许指定名称,要求,版本以及有关您所关注的组件的其他一些基本信息。但是,您需要将此文件保存在模块的根目录中。

composer.json使用了作曲家的通用架构,与一些要求:

元件描述
name格式完整的组件名称<vendor-name>/module-<component-name>。所有字母必须小写。使用中的破折号<component-name>分隔单词。
type对于模块,此值必须设置为magento2-module。其他可能的类型metapackagemagento2-thememagento2-language
autoload指定要加载的必要信息,例如[registration.php](extension-dev-guide / build / component-registration.html)。有关更多信息,请参见从Composer 自动加载

在Magento Marketplace中,有许多可接受的组件类型。type下表的下一列中,每种组件类型都对应一个作曲家。以及必须为该类型的组件添加到composer.json的type字段的值。

友好名称composer.json`type`
元包元包
模组magento2模块
主题magento2-主题
语言包magento2语言

让我们以下面的Metapackage示例为例

{
    "name": "magento/product-community-edition",
    "description": "A sample metapackage",
    "version": "2.0.0",
    "type": "metapackage",
    "require": {
        "php": "~5.5.0|~5.6.0|~7.0.0",
        "zendframework/zend-stdlib": "~2.4.6",
        "zendframework/zend-code": "~2.4.6",
        "zendframework/zend-server": "~2.4.6",
        "zendframework/zend-soap": "~2.4.6",
        "zendframework/zend-uri": "~2.4.6",
        "zendframework/zend-validator": "~2.4.6",
        "zendframework/zend-crypt": "~2.4.6",
        "zendframework/zend-console": "~2.4.6",
        "zendframework/zend-modulemanager": "~2.4.6",
        "zendframework/zend-mvc": "~2.4.6",
        "zendframework/zend-text": "~2.4.6",
        "zendframework/zend-i18n": "~2.4.6",
        "ext-ctype": "*",
        "ext-gd": "*",
        "ext-spl": "*",
        "ext-dom": "*",
        "ext-simplexml": "*",
        "ext-mcrypt": "*",
        "ext-hash": "*",
        "ext-curl": "*",
        "ext-iconv": "*",
        "ext-intl": "*",
        "ext-xsl": "*",
        "ext-mbstring": "*",
        "ext-openssl": "*"
        },
    "license": [
        "OSL-3.0",
        "AFL-3.0"
    ]
}

以下示例是composer.json模块的文件:

{
  "name": "magento/sample-module-newpage",
  "description": "A Magento 2 module that creates a new page",
  "type": "magento2-module",
  "version": "1.0.0",
  "license": [
    "OSL-3.0",
    "AFL-3.0"
  ],
  "require": {
    "php": "~5.5.0|~5.6.0|~7.0.0",
    "magento/framework": "~100.0.4"
  },
  "autoload": {
    "files": [ "registration.php" ],
    "psr-4": {
      "Magento\\SampleNewPage\\": ""
    }
  }
}

步骤2:使用来注册组件 registration.php

接下来,您必须通过来注册组件registration.php

步骤3:打包并生成组件

现在是使用扩展目录的时候了,让我们应用一个zip操作作为以下代码片段来添加一个包:

zip -r vendor-name_package-name-1.0.0.zip package-path/ -x 'package-path/.git/*'

压缩操作中有一些注意事项:

  • 单词之间不要留空格
  • 插入字母数字字符作为破折号

这样,您的扩展程序包将从任何有效的GitHub URL中获取。

步骤4:查看示例composer.json

档案:composer.json

{
  "name": "mageplaza/magento-2-seo-extension",
  "description": "Magento 2 SEO extension",
  "require": {
    "php": "~5.5.0|~5.6.0|~7.0.0",
    "mageplaza/core-m2": "dev-master"
  },
  "type": "magento2-module",
  "version": "1.1.1",
  "license": [
    "OSL-3.0",
    "AFL-3.0"
  ],
  "authors": [
    {
      "name": "Mageplaza",
      "email": "hi@mageplaza.com",
      "homepage": "https://www.mageplaza.com",
      "role": "Leader"
    }
  ],
  "autoload": {
    "files": [
      "registration.php"
    ],
    "psr-4": {
      "Mageplaza\\Seo\\": ""
    }
  }
}

档案:composer.json

{
  "name": "mageplaza/magento-2-social-login",
  "description": "Magento 2 Social Login Extension",
  "require": {
    "php": "~5.5.0|~5.6.0|~7.0.0"
  },
  "type": "magento2-module",
  "version": "1.0.0",
  "license": [
    "OSL-3.0",
    "AFL-3.0"
  ],
  "authors": [
    {
      "name": "Mageplaza",
      "email": "hi@mageplaza.com",
      "homepage": "https://www.mageplaza.com",
      "role": "Leader"
    }
  ],
  "autoload": {
    "files": [
      "registration.php"
    ],
    "psr-4": {
      "Mageplaza\\SocialLogin\\": ""
    }
  }
}


相关文章

0 0 投票数
文章评分
订阅评论
提醒
0 评论
内联反馈
查看所有评论