1

I need to get admin values to a PHP file located in Magento 2 root folder.

In Magento 1 I could do it by:

require ('./../../app/Mage.php');

How can I do this in Magento 2?

4
  • 1
    What do you mean by admin values? You want to access magento code in custom script ?
    – Keyur Shah
    Jan 15 '18 at 18:27
  • Sorry, I meant admin config values. Or calling a helper for that matter. But yes I want to access magento code in custom script Jan 15 '18 at 18:28
  • You mean store config values ?
    – Keyur Shah
    Jan 15 '18 at 18:29
  • I know how to get the values I need, the problem is that the magento code is not recognized in the root folder Jan 15 '18 at 18:31
2
<?php

ini_set('display_errors', 1);

use Magento\Framework\App\Bootstrap;

require __DIR__ . '/app/bootstrap.php';

$bootstrap = Bootstrap::create(BP, $_SERVER);

$obj = $bootstrap->getObjectManager();

$state = $obj->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');

$config = $obj->create('Magento\Framework\App\Config\ScopeConfigInterface');
echo $config->getValue('path/to/config', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
exit;

You just need to replace path/to/config with your config path

5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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