作成: app/code/Company1/Module1/composer.json
{
    "名前": "company1 / module-module1"、
    "説明": ""、
    "必要とする": {
        "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-directory": "100.0。*"
    }、
    "タイプ": "magento2-module"、
    "バージョン": "100.0.0"、
    「ライセンス」:[
        "OSL-3.0"、
        「AFL-3.0」
    ]、
    "オートロード":{
        "ファイル":["registration.php"]、
        "psr-4":{
            "Company1 \\ Module1 \\": ""
        }
    }
}
作成: app/code/Company1/Module1/registration.php
\ Magento \ Framework \ Component \ ComponentRegistrar :: register(
    \ Magento \ Framework \ Component \ ComponentRegistrar :: MODULE、
    'Company1_Module1'、
    __DIR__
);
作成: app/code/Company1/Module1/etc/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">
    <モジュール名= "Company1_Module1" setup_version = "2.0.0">
        <シーケンス>
            <モジュール名= "Magento_Directory" />
        </ sequence>
    </モジュール>
</構成>
モジュールの作成が完了しました。ヘルパーフォルダ内にヘルパークラスを作成します。
app/code/Company1/Module1/Helper/Data.php:
名前空間Company1 \ Module1 \ Helper;
クラスDataは\ Magento \ Framework \ App \ Helper \ AbstractHelperを拡張します
{
    公開関数someMethod()
    {
        1を返します。
    }
}
コントローラー内でヘルパークラスを使用する方法
$this->_objectManager->create('Company1\Module1\Helper\Data')->someMethod();
ブロック内でヘルパークラスを使用する方法
パブリック関数__construct(
        \ Magento \ Framework \ View \ Element \ Template \ Context $ context、
        \ Company1 \ Module1 \ Helper \ Data $ helper、
        配列$ data = []
    ){
        $ this-> helper = $ helper;
        親:: __ construct($ context、$ data);
    }
だから、$this->helper今、データのインスタンスです。
任意のクラスを上書きするには、設定を使用できます。
app/code/Company1/Module1/etc/di.xml:
<xml version = "1.0"?>
<config xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation = "urn:magento:framework:ObjectManager / etc / config.xsd">
    <preference for = "Magento \ Directory \ Helper \ Data" type = "Company1 \ Module1 \ Helper \ Data" />
</構成>
プラグインを使用することもできます。プラグインは、書き換えの競合を克服するための最良の方法です。プラグインの詳細情報の例