How to set Magento 2 modes (production, development)
To set a Magento 2 mode, use the following command:
|
1 |
magento setup:mode:set {mode} [-s|--skip-compilation] |

To set a Magento 2 mode, use the following command:
|
1 |
magento setup:mode:set {mode} [-s|--skip-compilation] |

Remove instruction is available in Magento 2. Please note that the layout merges in order shown in a module.xml/sequence section. Here is the instruction:
|
1 |
<?xml version="1.0"?> <layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/layout_generic.xsd"> <remove name="dashboard"/> </layout> |

You can learn about Magento 2 Request Flow from this presentation by Anton Kril:

Right in refresh .less files, since it “collects, processes and publishes source LESS files”:
|
1 |
php bin/magento dev:css:deploy |
You can also use dev mode during development. According to “Static view files are not cached; they are written to the Magento pub/static directory every time they’re called.”

In a case of a controller that extends Magento\Framework\App\Action\Action, it is possible to get the request with the aid of $this->getRequest()->getPost().
For a custom class, inject the request in the constructor:
|
1 |
<?php namespace Namespace\Module\Something; class ClassName { protected $request; public function __construct( \Magento\Framework\App\Request\Http $request, ....//rest of parameters here ) { $this->request = $request; ...//rest of constructor here } public function getPost() { return $this->request->getPost(); } } |

In Magento 2, the LESS PHP adapter is located in \lib\internal\Magento\Framework\View\Page\Config\Renderer, and you can easily replace it with another one (SASS for instance) by updating the following lines of code in the di.xml configuration:
|
1 |
<item name=”server_side_compilation” xsi:type=”string”>Magento\Framework\View\Page\Config\Renderer</item> |

By calling setTemplate method of course!
|
1 2 3 4 5 |
<referenceBlock name='copyright'> <action method='setTemplate'> <argument name='template' xsi:type='string'>Dfr_Backend::page/copyright.phtml</argument> </action> </referenceBlock> |

Being a boolean attribute, defer specifies that the script is executed after the page parsing. The attribute is aimed at external scripts only (the src attribute should be present). Find more information about defer .
Despite Magento 2 supports standard script deferring, it never uses defer in its core. To change the situation, you can use the following code:
|
1 2 3 4 5 6 7 8 |
<?xml version='1.0'?> <page xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' layout='admin-login' xsi:noNamespaceSchemaLocation='../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd'> <head> <script src='Dfe_Login::main.js' defer='defer'/> </head> </page> |

Go to Magento 2 Admin -> Stores -> Configuration -> Developer; select a specific store scope, and set “Template page hints” and “Add block names to hints” to Yes. You should get the following results:

Backend

Frontend
More tips from Magento 2 Developer’s Cookbook Continue Reading

First of all, I’d like to draw your attention to this blog post: . Having read it, you can learn more about code generation in Magento 2. Continue Reading