Модулі у файловій структурі Magento 2
Файли модулів у Magento 2 розташовані у 2 каталогах.
1. app/code/<VendorName>/<ModuleName>/ 2. vendor/<vendor-name>/<module-name>/
Назва постачальника — назва компанії/особи, яка розробила модуль. У деяких випадках назва постачальника може збігатися з назвою компанії замовника. Тому перед розробкою нового модуля слід узгодити назву. У прикладах ми використовуємо нашу назву — Magefan.
Файли модулів, розроблені на замовлення, або модулі від інших компаній, встановлені через FTP, знаходяться в папці app/code .
Папка vendor містить кореневі модулі, а також модулі, встановлені за допомогою майстра веб-налаштування або Composer. Ви знайдете кореневі модулі Magento у vendor/magento .
Цікаво знати:
У репозиторії Magento 2 (гілка dev) на GitHub ( https://github.com/magento/magento2 ) усі кореневі модулі знаходяться в папці app code/Magento. А всі бібліотеки PHP знаходяться в lib/internal/Magento.
Ця структура використовувалася під час розробки Magento 2, задовго до появи папки vendor та її офіційного релізу. Для зручності ця структура досі використовується на GitHub.
Структура модуля в Magento 2
├── Api // PHP interfaces ├── Block // PHP view classes, in MVC terminology. They contain methods used in .phtml templates; │ ├── Adminhtml // view-classes of the admin panel; │ └── SomeBlock.php // view-class (block) used in the storefront; │ ├── Controller // PHP controller-classes (part of MVC); │ └── Adminhtml // controller classes used in the admin panel; │ ├── Cron // PHP classes, which methods are called when performing cron-tasks;
├── Helper // PHP classes with auxiliary logic. Their methods are used in different parts of the module; ├── Model // PHP model classes (part of MVC); ├── Observer // PHP observers classes; ├── Plugin // PHP classes of interceptors; ├── Setup // PHP classes used when installing, updating and removing the module, allow you to change the data and structure of the database; ├── UI // PHP classes that work with UI-components; ├── etc // module configuration files; │ ├── adminhtml // configuration files that apply only to the admin panel; │ │ ├── admingws.xml // is used for the delimitation of rights at the Store View level (used only in Enterprise version (EE) of Magento 2); │ │ ├── di.xml // plugin settings, virtual types, rewriting models .; │ │ ├── menu.xml // is responsible for building the menu; │ │ ├── routers.xml // route settings; │ │ ├── system.xml // building a settings page Stores> Configuration; │ │ └── events.xml //observers settigns; │ │ │ ├── frontend // configuration files of the storefront;
│ │ ├── di.xml │ │ ├── events.xml │ │ ├── routers.xml │ │ └── events.xml │ │ │ ├── acl.xml // settings for delimitation of rights in the admin panel; │ ├── config.xml // default values for fields in Stores> Configuration;
│ ├── crontab.xml // settings of cron-tasks; │ ├── di.xml │ ├── webapi.xml // REST API settings; │ └── widget.xml // widget settings; │ ├── i18n // CSV localization files; │ ├── en_US.csv │ └── uk_UA.csv │ ├── view // view files: layouts, templates, js, css, html, images, fonts; │ ├── adminhtml // files used in the admin panel; │ ├── frontend // files used in the frontend; │ │ └── layout // xml layout files; │ │ └── templates // phtml-template files; │ │ └── web // static files; │ │ └── css │ │ └── images │ │ └── js │ │
│ └── base // view files used both on the storefront and admin panel;
│ ├── LICENSE.txt // file with the description of the license according to which the module is used; ├── README.md // description of module functionality; ├── composer.json // file that allows to install the module through composer later on; └── registration.php // file that registers the module in the system;
Ця структура не містить усіх можливих каталогів та файлів, які може містити модуль. Вона відображає лише часто використовувані компоненти модуля.
Ви можете самостійно дослідити структуру модулів у Magento 2. Для цього зверніть увагу на ці модулі:
- Magento_Cms (vendor/magento/module-cms)
- Magento_Catalog (vendor/magento/module-catalog)