I want to load that $configLoader without constructor i tried like below, but it's not working please tell me any other way to load that ConfigLoaderInterface without constructor.
<?php
namespace NameSpace\Module\Console\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Magento\Framework\Exception\LocalizedException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class CustomCommandClass extends Command
{
 public function __construct(
 \Magento\Framework\App\State $state,
 \Magento\Framework\ObjectManagerInterface $objectManager,
 \Magento\Framework\ObjectManager\ConfigLoaderInterface $configLoader
 ) {
 $state->setAreaCode('frontend'); //SET CURRENT AREA
 $objectManager->configure($configLoader->load('frontend')); //SOLUTION
 parent::__construct();
 }
}
I tried like below without constructor,
 $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');
$configLoader = $objectManager->create('Magento\Framework\ObjectManager\ConfigLoaderInterface');
$objectManager->configure($configLoader->load('frontend'));
 Teja Bhagavan Kollepara
 
 3,8275 gold badges33 silver badges69 bronze badges
 
 
 asked Dec 11, 2017 at 6:03
 
 
 
 Jeeva Chezhiyan 
 
 1,5085 gold badges20 silver badges39 bronze badges
 
 2 Answers 2
Please try using the object manager to test it even though is not recommended. Dependency injection must be used.
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$configLoader = $objectManager->get(\Magento\Framework\ObjectManager\ConfigLoaderInterface::class);
$objectManager->configure($configLoader->load('frontend'));
- 
 Can you share any link for brief detail about objectmanager?Jeeva Chezhiyan– Jeeva Chezhiyan2017年12月11日 07:57:15 +00:00Commented Dec 11, 2017 at 7:57
- 
 devdocs.magento.com/guides/v2.0/extension-dev-guide/… or alanstorm.com/magento_2_object_manager i will recommend.Nikolas– Nikolas2017年12月11日 08:05:51 +00:00Commented Dec 11, 2017 at 8:05
Delete var/generation and clear cache.
Run magento setup:upgrade
It may works!
 answered Dec 10, 2018 at 4:28
 
 
 
 Prema Karthik 
 
 4183 silver badges13 bronze badges
 
 default