Cheatography
https://cheatography.com
Magento 2 is a robust and feature-rich e-commerce platform with numerous actions and functionalities. However, I can provide a condensed cheatsheet outlining key actions across different areas of Magento 2 development. Please note that this is a simplified overview, and you may need to refer to Magento 2 official documentation for more in-depth information.
Module Structure
app/code/VendorName/ModuleName |
Basic module structure |
registration.php |
Module registration file |
etc/module.xml |
Module configuration file |
etc/frontend/routes.xml |
Define frontend routes |
etc/adminhtml/routes.xml |
Define admin routes |
|
Controller Actions
execute() |
Main controller action method |
ResultInterface |
Various result types (Json, Redirect, Page, etc.) |
getRequest() |
Retrieve request object |
getResponse() |
Retrieve response object |
|
Plugins
di.xml |
Define plugin configurations |
beforeMethod(), aroundMethod(), afterMethod(): |
Plugin methods |
proceed() |
Call the next method in the chain |
|
Magento CLI Commands
bin/magento module:enable Vendor_Module |
Enable a module |
bin/magento setup:upgrade |
Apply database schema and data changes |
bin/magento cache:flush |
Flushes cache including 3rd party modules |
bin/magento cache:clean |
Cleans Magento cache |
bin/magento indexer:reindex |
Reindex Data |
|
Models
load(), save(), delete() |
Basic CRUD operations |
__construct() |
Constructor method |
getData(), setData() |
Get and set model data |
getResource() |
Retrieve model's resource model |
|
Layout XML
<referenceContainer>, <referenceBlock> |
Reference existing containers/blocks. |
<block class="" template=""> |
Difine a block |
<arguments> |
Pass arguments to blocks |
<update handle=""> |
Apply layout updates. |
|
Observers
events.xml |
Define observer events |
execute(\Magento\Framework\Event\Observer $observer) |
Observer method. |
getEvent() |
getEvent() |
|
Templates
<?php echo $block->escapeHtml(__("Text")); ?> |
Output escaped text |
<?php echo $block->getUrl('route/controller/action'); ?> |
Generate URL |
<?php echo $block->getChildHtml(); ?> |
Output child block content |
|
Created By
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets
More Cheat Sheets by Bhavi