In Magento 1 I can use
require_once '../app/Mage.php';
$products = Mage::getModel('catalog/product')->getCollection();
Where is the new "/app/Mage.php
" in Magento 2?
What file I have to include in my external PHP file?
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityIn Magento 1 I can use
require_once '../app/Mage.php';
$products = Mage::getModel('catalog/product')->getCollection();
Where is the new "/app/Mage.php
" in Magento 2?
What file I have to include in my external PHP file?
Try this
In magento2 There no app.php
It have bootstrap.php which is main hero magento 2.
use Magento\Store\Model\Store;
use Magento\Store\Model\StoreManager;
require YoutmagetoDir. '/app/bootstrap.php';
/* set Parameters for application */
$opt['group'] = 'default';
$opt['standaloneProcessStarted'] = '0';
$params = $_SERVER;
/* you can out your store id here */
$params[StoreManager::PARAM_RUN_CODE] = 'admin';
$params[Store::CUSTOM_ENTRY_POINT_PARAM] = true;
/* create application */
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
/* the applocation
/** @var \Magento\Framework\App\Cron $app */
$app = $bootstrap->createApplication('Magento\Framework\App\Cron', ['parameters' => $opt]);
$bootstrap->run($app);
createApplication()
initialize magento application
On above example function we have send the store code(PARAM_RUN_CODE) as admin.
run()
function is execute the application