【发布时间】:2020-08-02 03:18:08
【问题描述】:
我在 Config 文件夹中创建了一个自定义配置文件。 配置/Elearning_config.php。现在我想使用 Codeigniter v4 的 Autoload.php 来加载它。如何做到这一点?
<?php namespace Config;
use CodeIgniter\Config\BaseConfig;
class Elearning_config extends BaseConfig
{
public $theme = 'theme/etreeks/';
}
【问题讨论】:
-
这样你可以加载 $Elearning_config = new \Config\Elearning_config();并使用像“$variable = $Elearning_config ->theme;”这样的变量
-
我想自动加载这个。我的意思是,我想在这里使用 Config/Autoload.php。你能解释一下吗?
-
我已经添加了答案检查一下。
-
自动加载加载类路径,与加载常量无关(我可以从你的 cmets 中看出答案)。如果您想定义常量而不是像这样在常量文件中定义它们:“defined('VARIABLE') || define('VARIABLE', 'value');”。然后,您可以在项目中的任何位置简单地回显 VARIABLE。
标签: php codeigniter frameworks codeigniter-4