0

I have created one custom command. That command is used when i need to generate some specific file. When i run setup:upgrade command then i give me error like "Area code not set".

Below is code example.

$this->state->setAreaCode(Area::AREA_FRONTEND); if ($input->getOption(self::GENERATE_NEW_MENU)) { $output->writeln('<info>Generating static navigation:<info>'); $generated = $this->abcModel->generateNavigation(1); if ($generated) { $output->writeln('<info> generated successfully.<info>'); } else { if ($generated->getMessage()) { $output->writeln('<error>Having issue while generating static navigation<error>'); $output->writeln('<error>Exception: ' . $generated->getMessage() . '<error>'); } } } 
9
  • For CLI command it is good to set Global area code instead of Frontend $this->appState->setAreaCode(\Magento\Framework\App\Area::AREA_GLOBAL); Commented Oct 16, 2023 at 10:01
  • Yes if i set AREA_GLOBAL or AREA_ADMINHTML then also it gives the same error. Commented Oct 16, 2023 at 10:06
  • try to put code into the try-catch & finally. Commented Oct 16, 2023 at 10:12
  • In which file you write above code? Commented Oct 16, 2023 at 10:18
  • @Harishkuril already added. Commented Oct 16, 2023 at 10:37

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.