Magento 2 How To Use Modal widget


Magento 2 How To Use the Modal widget

Creating a Magento widget is very easy and fast. All we have to do is include the required models.

Example:
Including HTML to load the model add div with id id='modal_content' and make it display none.

Example Code:

Magento Warning: ltrim() expects parameter 1 to be string,


Solution:


  1. Remove "di" folder located in var directory
  2. Go to your magento root folder
  3. Then execute the command php bin/magento setup:di:compile
  4. Give proper permissions to folders and files.

Magento 2 Setup:di:compile "No tokens were provided"

In the early days of Magento 2, I find it difficult to fix so after doing a lot of research. I am able to fix it by doing follow below solution.


Reason:

This error is due to empty PHP files that are present in your magneto installation.


Solution:

To find empty PHP files run

find * -type f -empty
on your terminal/putty or any other SSH client tool.


Thanks for reading! I hope it helps.

Exception #0 (Exception): Unable to proceed: the maintenance mode is enabled.

When we run production mode Magento enable maintenance mode first. And sometimes due to
any issue it stops working and we see above error.

Solution:

Simply disable maintenance mode using below commands

I hope it helps. Please share your suggestion or comments below.

Difference between "Flush Magento Cache" and "Flush Cache Storage" in magento?


In Magento. There are two commands that are used to flush/clear cache.

  • php bin/magento cache:flush
  • php bin/magento cache:clean


php bin/Magento cache:flush

It will remove all items from the default Magento cache (var/cache) and var/full_page cache.

php bin/magento cache:clean

It will remove all items from the cache. This is the equivalent of deleting the entire contents of the cache folder on the server. If your system uses an alternate cache location, any cached files used by other applications will be removed.


php bin/magento setup:upgrade Duplicate module entry


Explanation:
 
Another version of module already exist or same module already exist,So whenever we run the command
php bin/magento setup:upgrade 
Its will throw an error of duplicate module .
 

Solution:


  1. Open phpmyadmin and look for table name "setup_module"
  2. Look for module name in setup_module folder.
  3. Remove older module entry from table.
  4. Again execute the command bin/magento setup:upgrade
Hopefully it will be fixed .
Please comment and share your thoughts on issue.
 
 

Magento 2 How to add core or custom JavaScript file


There are so many ways we can include javascript in Magento 2.

Example: 1

   require(['jquery', 'jquery/ui'], function($){ 
     //your js code here  
   });


Example: 2
 
   require(['jquery'],function($){
     $(window).load(function() {
         alert('jquery working');
     });
   });