Magento2 moduleの作成
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
[[Magentoめも]]
#contents
*Magento2 moduleの作成 [#g12e8e6e]
Magento2はModules, Themes, Language Packagesの3つから成り...
app/code 以下に作成することでモジュールを作成できるようで...
*設定ファイルの作成 [#a68af654]
app/code/VendorName/ModuleName/ の構成になります。~
VendorName = Yassujp~
ModuleName = HelloWorld とします。
app/code/Yassujp/HelloWorld/etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-inst...
<module name="Yassujp_HelloWorld" setup_version="0.0...
</module>
</config>
app/code/Yassujp/HelloWorld/registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MOD...
'Yassujp_HelloWorld',
__DIR__
);
上記2つのファイルを作成したら、コンソールから以下のコマン...
php bin/magento setup:upgrade
ずらずら表示される中に Module 'Yassujp_HelloWorld': が確...
モジュールの一覧は以下で確認できます。~
STORES - Configuration - ADVANCED - Advanced
#ref(Yassujp_HelloWorld.png)
*管理画面に設定メニューを追加する [#e16228af]
idとfrontNameを定義します。
app/code/Yassujp/HelloWorld/etc/adminhtml/routes.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-inst...
<router id="admin">
<route id="yassujp_helloworld" frontName="yassuj...
<module name="Yassujp_HelloWorld" />
</route>
</router>
</config>
フォームを定義します。
app/code/Yassujp/HelloWorld/etc/adminhtml/system.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-inst...
<system>
<tab id="yassujp" translate="label" sortOrder="1...
<label>Yassujp</label>
</tab>
<section id="yassujp_helloworld" translate="labe...
<label>Yassujp_HelloWorld</label>
<tab>yassujp</tab>
<resource>Yassujp_HelloWorld::yassujp_hellow...
<group id="general" translate="label" type="...
<label>General</label>
<field id="enable" translate="label comm...
<label>Enable Hello World</label>
<source_model>Magento\Config\Model\C...
<comment>
Comment for `Enable Hello World`...
</comment>
</field>
<field id="block_label" translate="label...
<label>Block Label</label>
</field>
<field id="text_align" translate="label"...
<label>Text Align</label>
<source_model>Yassujp\HelloWorld\Mod...
</field>
</group>
</section>
</system>
</config>
Yes / No の選択肢は Magento\Config\Model\Config\Source\Ye...
vendor\magento\module-config\Model\Config\Source\Yesno.php
テキスト位置の選択肢は別途定義します。
app/code/Yassujp/HelloWorld/Model/Source/Align.php
<?php
namespace Yassujp\HelloWorld\Model\Source;
class Align implements \Magento\Framework\Option\ArrayIn...
{
public function toOptionArray()
{
return [['value' => 'left', 'label' => __('Left ...
}
public function toArray()
{
return ['left' => __('Left Position'), 'center' ...
}
}
STORES - Configuration にて作成したモジュールのフォームが...
#ref(Yassujp_HelloWorld2.png)
保存した設定は core_config_data テーブルに格納されます。
参考
-http://www.venustheme.com/how-to-create-magento-2-module/
-http://inchoo.net/magento-2/how-to-create-a-basic-module...
-https://blog.amasty.com/how-to-create-a-magento-2-extens...
終了行:
[[Magentoめも]]
#contents
*Magento2 moduleの作成 [#g12e8e6e]
Magento2はModules, Themes, Language Packagesの3つから成り...
app/code 以下に作成することでモジュールを作成できるようで...
*設定ファイルの作成 [#a68af654]
app/code/VendorName/ModuleName/ の構成になります。~
VendorName = Yassujp~
ModuleName = HelloWorld とします。
app/code/Yassujp/HelloWorld/etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-inst...
<module name="Yassujp_HelloWorld" setup_version="0.0...
</module>
</config>
app/code/Yassujp/HelloWorld/registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MOD...
'Yassujp_HelloWorld',
__DIR__
);
上記2つのファイルを作成したら、コンソールから以下のコマン...
php bin/magento setup:upgrade
ずらずら表示される中に Module 'Yassujp_HelloWorld': が確...
モジュールの一覧は以下で確認できます。~
STORES - Configuration - ADVANCED - Advanced
#ref(Yassujp_HelloWorld.png)
*管理画面に設定メニューを追加する [#e16228af]
idとfrontNameを定義します。
app/code/Yassujp/HelloWorld/etc/adminhtml/routes.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-inst...
<router id="admin">
<route id="yassujp_helloworld" frontName="yassuj...
<module name="Yassujp_HelloWorld" />
</route>
</router>
</config>
フォームを定義します。
app/code/Yassujp/HelloWorld/etc/adminhtml/system.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-inst...
<system>
<tab id="yassujp" translate="label" sortOrder="1...
<label>Yassujp</label>
</tab>
<section id="yassujp_helloworld" translate="labe...
<label>Yassujp_HelloWorld</label>
<tab>yassujp</tab>
<resource>Yassujp_HelloWorld::yassujp_hellow...
<group id="general" translate="label" type="...
<label>General</label>
<field id="enable" translate="label comm...
<label>Enable Hello World</label>
<source_model>Magento\Config\Model\C...
<comment>
Comment for `Enable Hello World`...
</comment>
</field>
<field id="block_label" translate="label...
<label>Block Label</label>
</field>
<field id="text_align" translate="label"...
<label>Text Align</label>
<source_model>Yassujp\HelloWorld\Mod...
</field>
</group>
</section>
</system>
</config>
Yes / No の選択肢は Magento\Config\Model\Config\Source\Ye...
vendor\magento\module-config\Model\Config\Source\Yesno.php
テキスト位置の選択肢は別途定義します。
app/code/Yassujp/HelloWorld/Model/Source/Align.php
<?php
namespace Yassujp\HelloWorld\Model\Source;
class Align implements \Magento\Framework\Option\ArrayIn...
{
public function toOptionArray()
{
return [['value' => 'left', 'label' => __('Left ...
}
public function toArray()
{
return ['left' => __('Left Position'), 'center' ...
}
}
STORES - Configuration にて作成したモジュールのフォームが...
#ref(Yassujp_HelloWorld2.png)
保存した設定は core_config_data テーブルに格納されます。
参考
-http://www.venustheme.com/how-to-create-magento-2-module/
-http://inchoo.net/magento-2/how-to-create-a-basic-module...
-https://blog.amasty.com/how-to-create-a-magento-2-extens...
ページ名: