Magento2.x 如何创建一个Module--模块声明

在magento1.9中想要新建一个模块需要在app/code文件中新建一个local文件夹,但是Magento2.x的app目录下是没有code文件的

所以我们需要先创建一个code文件下面放我们的项目目录,大致的目录结构和1.9差不多,不过新增了

1、registration.php(注册文件)

2、composer.json

3、view文件夹  (模板文件)

Sanv代表Vendor 、 Test代表Module

1、创建文件:app/code/Sanv/Test/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="Sanv_Test" setup_version="1.0.0"/>
</config>

2、创建文件:app/code/Sanv/Test/registration.php

<?php
MagentoFrameworkComponentComponentRegistrar::register(
    MagentoFrameworkComponentComponentRegistrar::MODULE,
    'Sanv_Test',
    __DIR__
);

3、查看module是否激活

     php bin/magento module:status  这时会显示已激活列表和未激活列表,未激活列表会显示Sanv_Test

     php bin/magento module:enable Sanv_Test  把模块激活 

  

原文地址:https://www.cnblogs.com/dongtong/p/6386491.html