I'm creating a file outside of the public_html folder. In Magento 1.x I could access Magento Core functionality be doing this:
Does anybody know the equivalent in Magento 2?
You can use Bootstrap to run Application which will return you response object. Here is official example from index.php file:
<?php require __DIR__ . '/app/bootstrap.php'; $params = $_SERVER; $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'website2'; $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website'; $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params); /** @var \Magento\Framework\App\Http $app *\ $app = $bootstrap->createApplication('Magento\Framework\App\Http'); $bootstrap->run($app);
Hope this helps.
Honestly, this is a much better answer IMO.
Demonstrates how to load up a standard Magento 2 abstract class using the bootloader.
And then, a somewhat more concrete example:
Check out the below link for a module which exposes the bootstrapped m2 application (and provides helper methods for accessing the layout).
Max is correct -- you need to first Bootstrap Magento (ideally into a new non-http application entry point).
From there you should be able to access the core classes from the object manager. The module is only needed for accessing layout components (which require a bit more magic to get working)