1
1

More than 3 years have passed since last update.

Magento2でエクステンションを作成する

Last updated at Posted at 2021-03-29

今回からニュース一覧を表示するエクステンションを作成していきます。今回はエクステンションの作成と有効化までです。

エクステンションを作成する

準備として以下のファイルを作成します。(作成するエクステンション名はVendor_Newsです。)

  • magento/app/code/Vendor/News/etc/module.xml
  • magento/app/code/Vendor/News/registration.php
magento/
   └ app/
      └ code/
         └ Vendor/
            └ News/
               ├ etc/
               │  └ module.xml
               └ registration.php

作成したファイルにエクステンションの雛形を記述します。エクステンション名以外は全て共有です。

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="Vendor_News" setup_version="1.0.0"/>
</config>
registration.php
<?php
Magento\Framework\Component\ComponentRegistrar::register(
    Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Vendor_News',
    __DIR__
);

エクステンションを有効化する

ここまででMagentoがエクステンションとして認識するようになりました。確認してみましょう。

$ php bin/magento module:status

List of disabled modules:
Vendor_News

このように表示されれば認識されています。それではエクステンションを有効化します。

$ php bin/magento module:enable Vendor_News

エクステンションの作成と有効化は以上です。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1