[英]How can I use config() function in the index.php file?
I use Laravel framework. 我使用Laravel框架。 I need to use
config()
function in the index.php
file (which exists in the public folder). 我需要使用
config()
函数中index.php
文件(在公用文件夹它存在)。 But when I call it, it throws this error: 但是当我调用它时,它会引发以下错误:
Fatal error: Call to undefined function config() in C:\\xampp\\htdocs\\myproject\\public\\index.php on line 2
致命错误:在第2行的C:\\ xampp \\ htdocs \\ myproject \\ public \\ index.php中调用未定义的函数config()
How can I fix it? 我该如何解决?
I'll not be able to use config()
in index.php
if no functionality were loaded at this point. 如果此时未加载任何功能,则无法在
index.php
使用config()
。
What you can do is to create simple functionality which will load data you need from config file. 您可以做的是创建简单的功能,该功能将从配置文件中加载所需的数据。 Or you can just hardcode value in
index.php
. 或者,您可以只在
index.php
值进行硬编码。 But I'd recommend you to find another way to achieve your goal and not touch index.php
at all. 但是我建议您找到另一种方法来实现您的目标,而不要完全接触
index.php
。
Update Laravel has already have maintenance mode functionality. 更新 Laravel已具有维护模式功能。
This is because Config
facades may not introduce for this index.php. 这是因为
Config
Facade可能不会为此index.php引入。 You add use Illuminate\\Support\\Facades\\Config;
您添加
use Illuminate\\Support\\Facades\\Config;
to use Config
method. 使用
Config
方法。
UPDATE UPDATE
Instead of Config
Try var_dump(getenv('APP_ENV'));
代替
Config
尝试var_dump(getenv('APP_ENV'));
, will help to use environment variable. ,将有助于使用环境变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.