How to Create Root Script in Magento 2
Magento 2 root script is the quick method to print something, or get data, or check something with the use of Object manager.
For example, if you want to get the order details and print it, you can create root script in Magento 2.
Or, you may want to check the location of a Magento 2 store in the hosting which can be done using the root script, say, test.php.
Hence, creating a custom Magento 2 root script can be a time saver for a developer and the post shows the method for the same.
Steps to Create Root Script in Magento 2:
1 2 3 4 5 6 7 8 9 10 |
<?php use Magento\Framework\App\Bootstrap; require 'app/bootstrap.php'; $bootstrap = Bootstrap::create(BP, $_SERVER); $objectManager = $bootstrap->getObjectManager(); $state = $objectManager->get('Magento\Framework\App\State'); $state->setAreaCode('frontend'); echo 'Test Script'; |
Any doubts about Magento 2 root scripts?
Feel free to mention them in the Comments section below. I’d be happy to help.
Do share the solution with Magento Community via social media.
Thank you.
Jignesh Parmar
An expert in his field, Jignesh is the team leader at Meetanshi and a certified Magento developer. His passion for Magento has inspired others in the team too. Apart from work, he is a cricket lover.
Prev
How to Add Header and Footer to Checkout Page in Magento 2
How to Display Percentage of Discount on Product List and View Page in Magento 2
Next