Answers.Body: <p>For those coming here using Craft 3, it's now <code>Craft::$app-&gt;getConfig()-&gt;general-&gt;devMode</code>.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-15T21:43:02.730Z
Answers.LastActivityDate: 2018-05-15T21:43:02.730Z
Answers.UserDisplayName: Nate Beaty
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-13T20:09:27.197Z
Answers.LastActivityDate: 2023-04-14T07:10:27.157Z
Answers.LastEditDate: 2023-04-14T07:10:27.157Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-13T18:43:40.040Z
Answers.LastActivityDate: 2023-04-13T18:43:40.040Z
Answers.UserDisplayName: Steve Mock
Answers.Body: <p>It's as simple as </p>
  
  <pre><code>if ( craft()-&gt;config-&gt;get( 'devMode' ) )
  {
   //do stuff
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-29T08:34:06.303Z
Answers.Text: 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.
Answers.UserDisplayName: Romain P.
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-29T08:37:51.263Z
Answers.Text: 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.
Answers.UserDisplayName: Ben Fleming
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-29T08:39:30.297Z
Answers.Text: `namespace Craft;` was already specified at the first line of my config/contactform.php file.
Answers.UserDisplayName: Romain P.
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-29T08:41:46.590Z
Answers.Text: Ok, I found the solution : craft()->config->get('devMode') does the job. Thank you !
Answers.UserDisplayName: Romain P.
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-29T08:41:53.813Z
Answers.Text: Oh I see, I misread the original error. I'm pretty sure you need to use `craft()->config->get('devMode')` instead
Answers.UserDisplayName: Ben Fleming
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-29T08:42:37.870Z
Answers.Text: Good spot - will update my answer.
Answers.UserDisplayName: Luke Pearce
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-29T17:11:25.753Z
Answers.Text: @LukePearce I think you're confusing Multi-Environment configuration and the [`environmentVariables`](https://craftcms.com/docs/config-settings#environmentVariables) config setting.
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-29T17:16:28.263Z
Answers.Text: I sure am. I'm tempted to just delete my answer and let someone else take care of it! ha
Answers.UserDisplayName: Luke Pearce
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-29T17:45:07.320Z
Answers.Text: Please, don’t! You well deserve the points for all this answer maintenance work, heh?!
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-29T08:28:56.847Z
Answers.LastActivityDate: 2016-06-29T17:17:35.857Z
Answers.LastEditDate: 2016-06-29T17:17:35.857Z
Answers.UserDisplayName: Luke Pearce
Body: <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>
  
Tags: <plugin-development><config><php><plugin-contactform><devmode>
Title: How can I check from a plugin config file if devMode is enabled?
ThreadText: # 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](https://github.com/pixelandtonic/ContactForm) 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.
  
  ```
  <?php
  
  $recipients = array(
      'devMode' => '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**: @username_4 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](https://craftcms.com/knowledge-base/what-dev-mode-does) from the PHP layer is [`App::devMode()`](https://docs.craftcms.com/api/v4/craft-helpers-app.html#public-methods):
  
  ```php
  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](https://craftcms.com/docs/4.x/config/general.html#devmode) 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`](https://craftcms.com/docs/4.x/dev/global-variables.html#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.
  
  ```
  
  
  ---
  
  