Check if Magento is running in production mode
-
12-04-2021 - |
Question
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?
Solution
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;
}
}
OTHER TIPS
Run below command in command line.
php bin/magento deploy:mode:show
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange