Dependency injection in Magento 2

Before diving in to the dependency injection we have to look in to an OOPS concept of “Coupling” and “Decoupling”

‘Coupling’ is a term that describes the relationship between two entities in a software system (usually classes).

When a class uses another class, or communicates with it, it’s said to ‘depend’ on that other class, and so these classes are ‘coupled’. At least one of them ‘knows’ about the other.

The idea is that we should try to keep the coupling between classes in our systems as ‘loose’ as possible: hence ‘loose coupling’ or sometimes ‘decoupling’ (although in English ‘decoupling’ would mean ‘no coupling at all’, people often use it to imply ‘loose coupling’ between entities).

Advertisements

White Screen no errors Magento 2

Compilation command

php  bin/magento setup:upgrade

php  bin/magento setup:di:compile

php  bin/magento setup:static-content:deploy -f

php bin/magento cache:clean

After running the above command if you face the blank page error for front end page and admin end page as some error like “Fatal error: Uncaught Error: Call to a member function setActive() on boolean”

If you face this error then clear var/cache folder and pub static folder

then run

php  bin/magento setup:upgrade

php bin/magento cache:flush

Configure Magento 2 in localhost to work faster for development purpose.

Follow the steps to make magento 2 to work faster in  localhost xampp

  1. Go to C:\xampp71\htdocs\magento2\app\etc\env.php change “MAGE_MODE => developer”
  2.  Go to Admin login dashboard Choose Store-> Configuration-> System -> Full page cache -> change “Caching Application” to Varnish cache.
  3. Go to admin login Click System Menu -> Cache Management -> Select all option and disable cache . so you dont want to run all magento commands while working in localhost.

Your current session has been expired. Magento 2 localhost version

Follow the below steps to solve this issue:

  • Find “admin/security/session_lifetime” in table core_config_data. if not exist create one and set value to 86400
  • Go to : admin_user_session table in MySql Set created_at column to ‘0’ and updated_atcolumn to ‘CURRENT_TIMESTAMP’ as it is.
  • Delete var/cache folder
  • Go to magento2 root folder index.php add the below code,  ini_set(‘memory_limit’,’-1′);