6

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

2 Answers 2

6

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'));
answered Dec 11, 2017 at 7:47
2
0

Delete var/generation and clear cache.

Run magento setup:upgrade

It may works!

answered Dec 10, 2018 at 4:28

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.