Hi friends, hope you are doing good. In today’s tutorial, I am going to share a very useful Magento code snippet to extend the Magento functionalities, please keep your close attention in this tutorial as I am going to share how to load the Magento 2 core in an external file.
Copy the below Magento code and use it in your custom PHP file to get the Magento 2 core functionality access.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <?php /** * how to load the Magento 2 core in external file */ ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); require 'app/bootstrap.php'; $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER); $app = $bootstrap->createApplication('Magento\Framework\App\Http'); $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); //adminhtml $objectManager->get('Magento\Framework\App\State')->setAreaCode('frontend'); $bootstrap->run($app); ?> |
Liked this program? Do Like & share with your friends.
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: magento code snippets, magento snippets, magento tutorial, magento tutorial for developer, magento tutorials