Skip to main content

Magento2 CLI

Magento2 CLI 




Back after a long break! Starting again with this blog because I found it the most important to understand if we are doing the magento development as magento commands play the most important role here. It really helps us a lot if we know that lĺwhich command we need to run on this action or after any changes. 


Let’s start with the basic commands that we use a lot of times during our development. 


  1. cache:clean or cache:flush


php bin/magento cache:clean

Or 

php bin/magento  cache:flush


Both of these commands are used to clean the cache of Magento2 so that your new changes can be reflected to your store. 

Using cache:clean it deletes all the enabled cache of magento2. Disabled caches are not affected with cache:clean but if you are doing cache:flush then it purges all the cache storage of magento wherever its enabled or disabled or it even deletes all the third party cache along with the magento cache. 


If you are doing any changes in admin configuration, layout xml file, ui_components, phtml etc then you need to clean or flush the magento cache. Try with the cache:flush if your changes are not reflected with cache:clean.


  1. setup:upgrade 


php bin/magento setup:upgrade


This command is basically used to update/create database schema or if you are updating and adding any data to the magento database. 

By default, setup:upgrade clears compiled code and cache, it deletes both generated/metadata and generated/code so that if you are adding or updating any dependency in constructor of a class, then running setup:upgrade will clear the compiled code and you need to run di:compile after this command to reflect your code modifications. Also if you know your code is doing anything related to database then setup:upgrade. Here is few more purposes :- 

  • If updating version of the module. 

  • Any changes in setup scripts like, InstallSchema, UpgradeSchema etc. 

  • New module installation. 



  1. di:compile 

php bin/magento setup:di:compile


This command is used to generate the classes of factories, proxies, repositories, plugins etc in generated/ folder of magento2. So whenever you are doing any code changes specially with factory methods, proxy, and adding or updating anything in plugins(Interceptors) then you need to run this command. 

This command is not required to run on developer mode as on that mode magento uses automatic code generation but if you are doing any changes like adding dependency in constructor of a class, or changes in di.xml etc in production mode then you need to run this command. 


This command clears generated/ folder prior to compiling. And please check the permissions of the generated folder after running the commands. 


This command consists of all of the following steps:- 


  • Application code generation (factories, proxies, and so on)

  • Area configuration aggregation (that is, optimized dependency injection configurations per area)

  • Interceptor generation (that is, optimized code generation of interceptors)

  • Interception cache generation

  • Repositories code generation (that is, generated code for APIs)

  • Service data attributes generation (that is, generated extension classes for data objects)

 

  1. static:content:deploy

 

php bin/magento setup:static-content:deploy

 

If you are doing any changes in HTML, CSS and JS then you need to delete files from pub/static folder and need to run static-content:deploy to deploy the files to pub/static directory so that your new changes will be reflected. 

Static view files are assets that are cached for a site as images, css, fonts etc. the files are placed inside a pub/static folder and few are cached in the var/view_processed folder. 

 

Will describe about a few more commands in the next blog. Hope this one will help you during the development process. 

 

 


Comments

Popular posts from this blog

How EAV Model Works in Magento2?

                         How EAV Model Works in Magento2?  EAV Model stands for Entity-Attribute-Value is a very important concept of magento2 to understand how the attributes of entities are stored and works in magento2.  EAV Model is described as :-  Entity - Entity refers to the data items such as customers,orders,catalog,category etc.  Attribute - Attributes of the entities like price is an attribute of the product(entity) is referred here is an attribute. Value - A value of the attribute as $20 is a value for price attribute is referred here is a value.  Use of EAV Model EAV(Entity-Attribute-Value) is used to create new attributes of entities such as products, categories etc. With the use of eav models we don’t need to change the structure of the core tables of attributes thus it increases the scalability of the system.  Let’s have a look at how eav works in Magento2 -  Eav model used many several tables to store the data of the entity attributes. The top most table for the e

Plugins in Magento2

Plugins in Magento2 Unlike Magento1, Magento2 introduces a whole new concept of Plugins or Interceptor. A plugin or interceptor is used to change the behaviour of the method of any class without affecting the actual class. This is a very powerful way to customize the core classes of Magento2.  Plugins are one of the customization methods in Magento2. In plugins, there is a design pattern called “Interception” which means “Inserting code dynamically without changing original class behaviour” and this is what plugins exactly do in Magento2. Plugins modify the behaviour of a plugin class function by intercepting a function call and adding code before, after and around that function’s call.  Plugins are used with public methods only.  Declaring Plugins To declare plugins in Magento2, we have to create di.xml according to the specific area.  Create di.xml inside Vendor/Module/etc for global.   < config >     < type name = "{ObservedType}" >       < plugin name