douliangpo0128 2019-02-11 11:43
浏览 161
已采纳

Codeigniter - 包含env文件时出现问题

I'm trying to include .env file in Codeigniter 3 by following steps:

integrating.env files in CodeIgniter 3.0 using hooks

But, it returns the following error

A PHP Error was encountered Severity: 4096

Message: Argument 1 passed to Dotenv\Dotenv::__construct() must be an instance of Dotenv\Loader, string given, called in /application/config/hooks.php on line 5 and defined

Filename: src/Dotenv.php

Line Number: 31

My /application/config/hooks.php file is configured in the same way as indicated in the tutorial:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

$hook['pre_system'] = function() {
    $dotenv = new Dotenv\Dotenv(APPPATH);
    $dotenv->load();
};

I had done a quick research and unable to find a perfect solution for the problem occurred, Can you guys please help me to find out a solution?

  • 写回答

3条回答 默认 最新

  • douyingbei1458 2019-02-15 12:47
    关注

    I was able to install phpdotenv in a different way from the instructions in the first tutorial.
    In this tutorial installation is done without the use of Composer:

    PHPDotenv for CodeIgniter (Installation without Composer)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?