create test.php file in magento2 root, i want require baseUrl also i try to
require __DIR__ . '/app/bootstrap.php';
but it's not work
create test.php file in magento2 root, i want require baseUrl also i try to
require __DIR__ . '/app/bootstrap.php';
but it's not work
It's work
use Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$obj = $bootstrap->getObjectManager();
$obj->get('\Magento\Framework\App\State')->setAreaCode('frontend'); // for remove Area code is not set error
$storeManager = $obj->get('\Magento\Store\Model\StoreManagerInterface');
echo $baseUrl=$storeManager->getStore()->getBaseUrl();
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
$baseUrl = $storeManager->getStore()->getBaseUrl();
OR To get base dir path use ::
$myModuleDir = BP . '/app/code/MyVendor/MyModule';