0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

CakePHP4で.envが反映されないときの対処

0
Posted at

やりたいこと

  • CakePHP4で.envに設定した値をControllerで読み込んで使いたい。

問題点

  • .env に設定した値をController側で取得できない。

前提

  • .env への設定やController側での読み込み処理は正しく実装されている。

原因

config/bootstrap.php
に下記の記述がある。デフォルトでコメントアウトされている。
このコメントアウトを外して有効にしないと、.envが反映されない。

 if (!env('APP_NAME') && file_exists(CONFIG . '.env')) {
     $dotenv = new \josegonzalez\Dotenv\Loader([CONFIG . '.env']);
     $dotenv->parse()
         ->putenv()
         ->toEnv()
         ->toServer();
 }
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?