High-level Magento Architecture. Magento 2 vs Magento 1

High-level Magento Architecture. Magento 2 vs Magento 1

The article is dedicated to the basic Magento architecture as well as its comparison with both Magento versions.  As for Magento 1 structure, all relevant description you can find in the article Magento Module StructureAs for Magento 2 structure, it is shown in the picture below.

High-level Magento architecture. Magento 2 vs Magento 1

If compared with Magento 1, the structure has changed. But registration.php and etc/module.xml are still obligatory.

In Magento 2 the structure is not as strict as in Magento 1, so the folder may have any subfolder. Additionally, the developer is allowed to place a file in any subfolder. However, the listed folders correspond to different class types, so this structure is historical and should be retained.

One of the significant distinctions between Magento 1 and Magento 2 is the lack of codepools in Magento 2. The code here can be placed in the app/code and vendor directories.

The most general module structure in Magento 2 is the following:

  • Block: For blocks
  • Controller: For controller actions
  • Helper: For helpers
  • Model: Where models and resource models are located
  • Setup: For installing and upgrading scripts
  • View: For layout XML files, templates, and static view files

NOTE: The file name should repeat the folder structure, starting from <Vendor>/<ModuleName>. For example, the PHP class in the file app/code/Magento/Catalog/Model/Product.php should have the name Magento/Catalog/Model/Product.

Let’s see how Magento 2 processes the request. In Magento 2 we’ll initiate the request by going to the index.php file.

The first part of the code is similar to the code we’ve had in Magento 1. It uses the bootstrap.php file, which requires autoload.php.

Note that the autoload file registers the autoloader:

The autoloader is quite important because all your classes will be downloaded with it. Magento has a few autoloaders, but the main one (\Composer\Autoload\ClassLoader) is similar to the one we’ve had in Magento 1. It takes the path to the class and converts it to the physical path to the file.

In Magento 2, we no longer have a factory method, that’s why it calls all classes by full names making the process a bit easier.



Post a new comment

top
BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *