<p>For those coming here using Craft 3, it's now <code>Craft::$app-&gt;getConfig()-&gt;general-&gt;devMode</code>.</p>

CC BY-SA 4.0
2018-05-15T21:43:02.730Z
2018-05-15T21:43:02.730Z
Nate Beaty
<p>Since Craft 4.0, the recommended method to test if Craft is running in <a href="https://craftcms.com/knowledge-base/what-dev-mode-does" rel="nofollow noreferrer">dev mode</a> from the PHP layer is <a href="https://docs.craftcms.com/api/v4/craft-helpers-app.html#public-methods" rel="nofollow noreferrer"><code>App::devMode()</code></a>:</p>
<pre class="lang-php prettyprint-override"><code>use craft\helpers\App;

$devMode = App::devMode();
</code></pre>
<p>Apart from <code>App::devMode()</code> being faster (and less verbose to type), the big difference between it and <code>Craft::$app-&gt;getConfig()-&gt;getGeneral()-&gt;devMode</code> is that the latter will simply return whatever value the <a href="https://craftcms.com/docs/4.x/config/general.html#devmode" rel="nofollow noreferrer"><code>devMode</code> config setting</a> is currently set to, whereas <code>App::devMode()</code> will tell you <em>if Craft is actually running in dev mode or not</em>, by returning the value for the <code>YII_DEBUG</code> constant.</p>
<p>In practice, the values for the <code>devMode</code> config setting and the <code>YII_DEBUG</code> constant will almost always be the same - but not necessarily, and there are edge cases where the nuance between the two can make a difference.</p>
<p>Internally, Craft uses <code>App::devMode()</code> in most cases.</p>
<p>If working in Twig, <code>App::devMode()</code> is not available, but the global <a href="https://craftcms.com/docs/4.x/dev/global-variables.html#devmode" rel="nofollow noreferrer"><code>devMode</code></a> variable can be used instead, which will return the same thing (i.e. the <code>YII_DEBUG</code> constant's value):</p>
<pre><code>{% if devMode %}
   We are debuggin'
{% endif %}
</code></pre>

CC BY-SA 4.0
2023-04-13T20:09:27.197Z
2023-04-14T07:10:27.157Z
2023-04-14T07:10:27.157Z
Mats Mikkel Rummelhoff
<p>For those coming here &gt;= Craft 3.5, it's now</p>
<pre><code>Craft::$app-&gt;getConfig()-&gt;getGeneral()-&gt;devMode.
</code></pre>

CC BY-SA 4.0
2023-04-13T18:43:40.040Z
2023-04-13T18:43:40.040Z
Steve Mock
<p>It's as simple as </p>

<pre><code>if ( craft()-&gt;config-&gt;get( 'devMode' ) )
{
 //do stuff
}
</code></pre>

CC BY-SA 3.0
2016-06-29T08:34:06.303Z
Using this, I get this error : `The property « Craft\ConfigService.devMode » is undefined.`. Yes, I'm using environment variables, but following the other answer there is no devMode data that I can get from `the craft()->config->get('environmentVariables')`, while devMode is enabled in my current dev environment.
Romain P.
CC BY-SA 3.0
2016-06-29T08:37:51.263Z
This is because you're not in the Craft namespace. Included in most files is a `namespace Craft;` declaration at the top of the file, but in config files this is not usually there. You could either add this namespace declaration to your config file, or use `\Craft\craft()->config->devMode` instead.
Ben Fleming
CC BY-SA 3.0
2016-06-29T08:39:30.297Z
`namespace Craft;` was already specified at the first line of my config/contactform.php file.
Romain P.
CC BY-SA 3.0
2016-06-29T08:41:46.590Z
Ok, I found the solution : craft()->config->get('devMode') does the job. Thank you !
Romain P.
CC BY-SA 3.0
2016-06-29T08:41:53.813Z
Oh I see, I misread the original error. I'm pretty sure you need to use `craft()->config->get('devMode')` instead
Ben Fleming
CC BY-SA 3.0
2016-06-29T08:42:37.870Z
Good spot - will update my answer.
Luke Pearce
CC BY-SA 3.0
2016-06-29T17:11:25.753Z
@LukePearce I think you're confusing Multi-Environment configuration and the [`environmentVariables`](https://craftcms.com/docs/config-settings#environmentVariables) config setting.
carlcs
CC BY-SA 3.0
2016-06-29T17:16:28.263Z
I sure am. I'm tempted to just delete my answer and let someone else take care of it! ha
Luke Pearce
CC BY-SA 3.0
2016-06-29T17:45:07.320Z
Please, don’t! You well deserve the points for all this answer maintenance work, heh?!
carlcs
CC BY-SA 3.0
2016-06-29T08:28:56.847Z
2016-06-29T17:17:35.857Z
2016-06-29T17:17:35.857Z
Luke Pearce
<p>Using the Pixel &amp; Tonic <a href="https://github.com/pixelandtonic/ContactForm" rel="noreferrer">Contact Form</a> plugin, I added a config file (<code>config/contactform.php</code>) to override plugin settings from the CP.</p>

<p>I would like to change some settings if devMode is enabled : recipients from the contact form plugin, to separate my tests addresses from my client addresses.</p>

<pre><code>&lt;?php

$recipients = array(
    'devMode' =&gt; 'example@domain.com,example@domain.com',
    'prodMode' =&gt; 'john@doe.com,jean@dupont.com'
);

if (devMode == true) {
    $recipients = $recipients['devMode'];
} else {
    $recipients = $recipients['prodMode'];
}

return array(
    'toEmail' =&gt; ($recipients ?: null),
</code></pre>

<p>How can I check if <strong>devMode == true</strong>? Can I access to this value using <code>craft()-&gt;config</code> or something else that?</p>

<plugin-development><config><php><plugin-contactform><devmode>
How can I check from a plugin config file if devMode is enabled?
# How can I check from a plugin config file if devMode is enabled?

(Asked by: username_0 on 2016-06-29)

Using the Pixel & Tonic Contact Form plugin, I added a config file (config/contactform.php) to override plugin settings from the CP.
I would like to change some settings if devMode is enabled : recipients from the contact form plugin, to separate my tests addresses from my client addresses.
 'example@domain.com,example@domain.com',
    'prodMode' => 'john@doe.com,jean@dupont.com'
);

if (devMode == true) {
    $recipients = $recipients['devMode'];
} else {
    $recipients = $recipients['prodMode'];
}

return array(
    'toEmail' => ($recipients ?: null),

How can I check if devMode == true? Can I access to this value using craft()->config or something else that?

**Tags:** plugin-development, config, php, plugin-contactform, devmode

---

## 4 answers

### Answer by username_4 on 2016-06-29. Score: 8 | Accepted answer

It's as simple as 
if ( craft()->config->get( 'devMode' ) )
{
 //do stuff
}

> **Comments:**
> **username_0**: Using this, I get this error : `The property « Craft\ConfigService.devMode » is undefined.`. Yes, I'm using environment variables, but following the other answer there is no devMode data that I can get from `the craft()->config->get('environmentVariables')`, while devMode is enabled in my current dev environment.  
> **username_5**: This is because you're not in the Craft namespace. Included in most files is a `namespace Craft;` declaration at the top of the file, but in config files this is not usually there. You could either add this namespace declaration to your config file, or use `\Craft\craft()->config->devMode` instead.  
> **username_0**: `namespace Craft;` was already specified at the first line of my config/contactform.php file.  
> **username_0**: Ok, I found the solution : craft()->config->get('devMode') does the job. Thank you !  
> **username_5**: Oh I see, I misread the original error. I'm pretty sure you need to use `craft()->config->get('devMode')` instead  
> **username_4**: Good spot - will update my answer.  
> **username_6**: @LukePearce I think you're confusing Multi-Environment configuration and the [`environmentVariables`](https://craftcms.com/docs/config-settings#environmentVariables) config setting.  
> **username_4**: I sure am. I'm tempted to just delete my answer and let someone else take care of it! ha  
> **username_6**: Please, don’t! You well deserve the points for all this answer maintenance work, heh?!  

---

### Answer by username_1 on 2018-05-15. Score: 14

For those coming here using Craft 3, it's now `Craft::$app->getConfig()->general->devMode`.


---

### Answer by username_2 on 2023-04-13. Score: 2

Since Craft 4.0, the recommended method to test if Craft is running in dev mode from the PHP layer is App::devMode():
use craft\helpers\App;

$devMode = App::devMode();

Apart from App::devMode() being faster (and less verbose to type), the big difference between it and Craft::$app->getConfig()->getGeneral()->devMode is that the latter will simply return whatever value the devMode config setting is currently set to, whereas App::devMode() will tell you if Craft is actually running in dev mode or not, by returning the value for the YII_DEBUG constant.
In practice, the values for the devMode config setting and the YII_DEBUG constant will almost always be the same - but not necessarily, and there are edge cases where the nuance between the two can make a difference.
Internally, Craft uses App::devMode() in most cases.
If working in Twig, App::devMode() is not available, but the global devMode variable can be used instead, which will return the same thing (i.e. the YII_DEBUG constant's value):
{% if devMode %}
   We are debuggin'
{% endif %}


---

### Answer by username_3 on 2023-04-13. Score: 1

For those coming here >= Craft 3.5, it's now
Craft::$app->getConfig()->getGeneral()->devMode.


---

