0

I am creating a custom store implementation and I need to check if the store is in production mode or not via code. What is the fastest way to achieve this?

6
  • check my answer. – Jinesh Mar 20 '20 at 11:06
  • you want to without code right ??? – Mohit Patel Mar 20 '20 at 11:09
  • @Jinesh now i've the office server down, i will implement your solution in the afternoon. – Alfredo Lanzetta Mar 20 '20 at 11:13
  • @mohit-patel there is some alternative to get it? – Alfredo Lanzetta Mar 20 '20 at 11:14
  • so my question is have you want production mode using command line or programatically? – Jinesh Mar 20 '20 at 11:24
0

Try this code

$om = \Magento\Framework\App\ObjectManager::getInstance();
/** @return \Magento\Framework\App\State */
$state = $om->get('Magento\Framework\App\State');
/** @var bool $isDeveloperMode */
$isDeveloperMode = \Magento\Framework\App\State::MODE_DEVELOPER === $state->getMode();

You can get using magento coding standard

protected $_appState;

public function __construct( \Magento\Framework\App\State $appState )
{
    $this->_appState = $appState;
}

public function doSomething() {
    switch ( $this->_appState->getMode() ) {
        case \Magento\Framework\App\State::MODE_DEFAULT:
            // Action for default mode
            break;
        case \Magento\Framework\App\State::MODE_PRODUCTION:
            // Action for production mode
            break;
        case \Magento\Framework\App\State::MODE_DEVELOPER:
            // Action for developer mode
            break;
    }
}
1

Run below command in command line.

php bin/magento deploy:mode:show

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.