Warning: Cannot modify header information - headers already sent by (output started at /www/wwwroot/sbboke.com/wp-content/plugins/wordpress-seo/src/integrations/front-end-integration.php:409) in /www/wwwroot/sbboke.com/wp-content/themes/pacify/content-single.php on line 5

Magento 2区域与模块

区域可以理解为一个逻辑组件,可以帮助您组织代码以优化请求的处理。区域通常用于简化Web服务调用。这可以通过仅加载特定区域的相关代码来完成。Magento定义的每个默认区域都可以包含完全不同的进程URL和请求代码。例如,当您调用REST Web服务调用时,您可以标识一个单独的区域,该区域加载其范围仅限于回答REST调用的代码。

6 Magento地区类型

1. Magento Admin:adminhtml

index.php或者pub/index.php是该adminhtml地区的切入点。管理商店所需的所有代码都将包含在此“管理”面板区域中。如果要查看在“管理”面板中工作时将看到的组件的所有代码,则可以访问该/app/design/adminhtml目录。

2. Storefront: frontend

Storefront地区的入口点是index.phppub/index.php。要定义店面外观,可以在此区域中找到模板和布局文件。

3. Basic: base

您可以使用基本为它们不存在于文件中的替代adminhtmlfrontend地区。

4. Cron: crontab

crontab区域将始终由\Magento\Framework\App\Croncron.php中的类加载

5. Web API REST

要进入Web API REST(webapi_rest)区域,您可以找到它的入口点index.phppub/index.php。该区域有一个前端控制器,可以理解基于REST的URL的URL查找方式。

6. Web API SOAP:webapi_soap

Web API SOAP区域的入口点是index.phppub/index.php

区域与模块

在区域中可见和可访问的资源以及区域的行为将由模块定义。多个区域可能受同一模块的影响。例如,RMA模块的一部分将adminhtml在前端区域中表示。

如果您的模块在不同的区域工作,请确保它需要具有单独的行为并查看每个区域的组件。

每个区域都将在模块中声明自己。此外,区域的所有资源也将位于同一模块中。

此外,您还可以启用或禁用模块中的区域。一旦启用了模块,它就会将区域的路由器注入应用程序的一般路由过程。相反,如果禁用该模块,则不会加载该区域的路由器。因此,区域的资源和特定功能将不可用。

事实:

  • 模块的其他区域不应影响模块。
  • 禁用某个区域时,不会导致与该区域相关的模块被禁用。
  • 区域将在名为Dependency Injection framework di.xml的文件中注册。

前端区域的示例

在本指南中,我们将向您展示如何将前端主题创建为前端区域。

主题文件夹结构

app/design/frontend/mageplaza/
├── ultimate/
│   ├── etc/
│   │   ├── view.xml
│   ├── web/
│   │   ├── images
│   │   │   ├── logo.svg
│   ├── registration.php
│   ├── theme.xml
│   ├── composer.json

创建一个app/design/frontend/mageplaza/theme.xml这样的文件:

<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../lib/internal/Magento/Framework/Config/etc/theme.xsd">
  <title>Mageplaza Ultimate</title>
  <parent>Magento/blank</parent>
</theme>

宣布你的主题

现在我们有了文件夹app/design/frontend/mageplaza/ultimate,现在创建一个名为的文件theme.xml来定义关于主题的基本信息,例如:名称,父主题(如果你的主题继承现有主题),预览图像

<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
     <title>Mageplaza Ultimate</title> <!-- your theme's name -->
     <parent>Magento/blank</parent> <!-- the parent theme, in case your theme inherits from an existing theme -->
     <media>
         <preview_image>media/preview.jpg</preview_image> <!-- the path to your theme's preview image -->
     </media>
 </theme>

创建注册文件

您可以将以下内容添加registration.php到Magento 2的主题中

文件: app/design/frontend/mageplaza/registration.php

<?php

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::THEME,
    'frontend/mageplaza/ultimate',
    __DIR__
);

您应该将 mageplaza Ultimate更改为您的供应商,主题名称

相关文章

0 0 投票数
文章评分
订阅评论
提醒
0 评论
内联反馈
查看所有评论