Ist die .env-Datei von Laravel nur gültig, wenn sie im Konfigurationsordner aufgerufen wird?
给我你的怀抱
给我你的怀抱 2017-06-13 09:24:33
0
2
869

Der Autor schreibt eine Artisan命令,在AppConsole下的command文件内调用getenv方法,来获取.env-Konfiguration und das Ergebnis gibt null

zurück

Aber mit der config/services.php获取.env的配置,再在AppConsole下的command文件调用config-Methode können Sie den gewünschten Umgebungsvariablenwert erhalten.

给我你的怀抱
给我你的怀抱

Antworte allen(2)
黄舟

官方的建议是,在config里面调用env,在别的地方调用config。

这其实是个大坑,我第一次写laravel的时候就发现这个env在控制器里面就是读不出来。(也不是百分百读不出来,是执行了 php artisan config:cache 之后读不出来)

Caching And Env

If you are using the config:cache command during deployment, you must make sure that you are only calling the env function from within your configuration files, and not from anywhere else in your application.

If you are calling env from within your application, it is strongly recommended you add proper configuration values to your configuration files and call env from that location instead, allowing you to convert your env calls to config calls.

摘自 https://laravel.com/docs/5.2/...

Peter_Zhu

Laravel 有辅助函数 env() 呀= =

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!