0

i am working in command class, when i inject a class in constructor and run di complie, it gives error of "area code is not set", when i remove injected class form the constructor then my command is working, taking argume

2
  • can you please share code here ?
    – Msquare
    Nov 20 at 21:00
  • share the code of class, which show this error? Nov 21 at 10:56

1 Answer 1

0

Inject \Magento\Framework\App\State in your __construct and following code into your execute function

try {
     $this->state->getAreaCode();
} catch (\Exception $exception) {
    $this->state->setAreaCode(\Magento\Framework\App\Area::AREA_ADMINHTML);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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