How to create a root script in Magento 2?

How to create a root script in magento 2?

In this tutorial, we will see how to create a custom root script in our Magento 2 and use it to perform Magento 2 specific operations.

For this create a file inside the Magento root directory with some unique name based on the activity you are going to perform, suppose you want to get a customer’s email by id then name it like getCustomerEmailById.php

You can use Object Manager in the custom script to get objects of specific classes.

Here is an example of a custom root script, which is used to fetch customer email from a given customer ID.

Example :

After creating this file, Now you can call it using PHP in the terminal by specifying the file name as below.

It will print customer email if exists.

Leave a Reply

Your email address will not be published. Required fields are marked *