3

This question already has an answer here:

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?

marked as duplicate by Marius Jul 22 '15 at 12:19

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

Call of Application:

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.