Yireo_Webp2 项目使用教程
1. 项目的目录结构及介绍
Yireo_Webp2 是一个用于 Magento 2 的模块,旨在添加 WebP 支持。以下是该项目的目录结构及其介绍:
Yireo_Webp2/
├── etc/
│ ├── module.xml
│ ├── config.xml
│ └── di.xml
├── registration.php
├── Helper/
│ └── Data.php
├── Model/
│ └── Converter.php
├── Observer/
│ └── LayoutGenerateBlocksAfter.php
├── Plugin/
│ └── SwatchRenderer.php
├── Setup/
│ └── UpgradeSchema.php
├── view/
│ ├── frontend/
│ │ ├── layout/
│ │ │ └── catalog_category_view.xml
│ │ └── templates/
│ │ └── picture.phtml
│ └── adminhtml/
│ ├── layout/
│ │ └── system_config_edit.xml
│ └── templates/
│ └── config.phtml
└── composer.json
etc/
: 包含模块的配置文件。module.xml
: 定义模块的基本信息。config.xml
: 包含模块的配置选项。di.xml
: 依赖注入配置文件。
registration.php
: 用于注册模块。Helper/
: 包含辅助类。Data.php
: 提供模块的辅助功能。
Model/
: 包含核心逻辑。Converter.php
: 负责图像转换的核心逻辑。
Observer/
: 包含事件观察者。LayoutGenerateBlocksAfter.php
: 在布局生成块后执行的观察者。
Plugin/
: 包含插件。SwatchRenderer.php
: 用于处理颜色选择器的插件。
Setup/
: 包含数据库安装和升级脚本。UpgradeSchema.php
: 数据库升级脚本。
view/
: 包含前端和后台的视图文件。frontend/
: 前端视图文件。layout/
: 布局文件。templates/
: 模板文件。
adminhtml/
: 后台视图文件。layout/
: 布局文件。templates/
: 模板文件。
composer.json
: 定义模块的依赖关系。
2. 项目的启动文件介绍
Yireo_Webp2 项目的启动文件主要是 registration.php
,它负责在 Magento 2 系统中注册该模块。
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Yireo_Webp2',
__DIR__
);
该文件使用 Magento\Framework\Component\ComponentRegistrar
类将模块注册到 Magento 2 系统中。
3. 项目的配置文件介绍
Yireo_Webp2 项目的配置文件主要位于 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">
<module name="Yireo_Webp2" setup_version="1.0.0"/>
</config>
config.xml
: 包含模块的配置选项,例如是否启用 WebP 支持。
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<yireo_webp>
<enabled>1</enabled>
</yireo_webp>
</default>
</config>
di.xml
: 依赖注入配置文件,定义依赖关系和插件。
<?xml version="1.0"?>
<config xmlns:xsi="http