更新 CodeIgniter 4 后出现错误:不再使用“system/bootstrap.php”

问题描述 投票:0回答:1

将我的 CodeIgniter 应用程序更新到版本 4.5.1 后,我收到一条错误,指示“system/bootstrap.php”文件不再使用。

错误内容如下:

“此“system/bootstrap.php”不再使用。如果您看到此内容 错误消息,升级未完成。”

我还遇到了一个未定义的 ENVIRONMENT 变量的问题,我似乎已经解决了。 经过我的尝试。

我按照官方文档中所述升级到 CodeIgniter 4.5.0 指南。

1 - 我运行了 compose update 命令来更新依赖项

2 - 将 public/index.php 和spark.php 文件从vendor/codeigniter4/framework/public 目录复制到我的public 目录,并检查所有对system/bootstrap.php 的引用是否已从我的public/index 中删除。 php 文件。

我将这些行添加到我的index.php 文件中:

// Load environment settings from .env files into $_SERVER and $_ENV
require_once SYSTEMPATH . 'Config/DotEnv.php';
(new CodeIgniter\Config\DotEnv(ROOTPATH))->load();

// Define ENVIRONMENT
if (! defined('ENVIRONMENT')) {
    define('ENVIRONMENT', env('CI_ENVIRONMENT', 'production'));
}

尽管执行了这些步骤,错误仍然存在。我也尝试过重建我的 Docker 容器,但这并没有解决问题。

如何解决此错误并完成我的应用程序到 CodeIgniter 4.5.1 的升级。 ?

更新:

我创建了一个新的 CodeIgniter 项目。并复制/粘贴我的项目中的所有配置。一切都没有改变。 我尝试对 public/index.php 和 Spark 文件进行评论,但出现了同样的错误。我认为我所有的改变都没有任何作用...

php codeigniter codeigniter-4
1个回答
0
投票

从您添加的 index.php 和 Spark 中删除这些行:

// Load environment settings from .env files into $_SERVER and $_ENV
require_once SYSTEMPATH . 'Config/DotEnv.php';
(new CodeIgniter\Config\DotEnv(ROOTPATH))->load();

// Define ENVIRONMENT
if (! defined('ENVIRONMENT')) {
    define('ENVIRONMENT', env('CI_ENVIRONMENT', 'production'));
}

这些是在/Boot.php中定义的,所以你不需要添加它们


当文档 https://codeigniter4.github.io/userguide/installation/upgrade_450.html#index-php-and-spark 说...

您必须合并更新的版本

...我认为这意味着将当前 index.php 中的任何自定义项添加到新的 4.5.0 index.php 中。一个例子是更改应用程序文件夹所在的位置......

// LOAD OUR PATHS CONFIG FILE
// This is the line that might need to be changed, depending on your folder structure.
require FCPATH . '../app/Config/Paths.php';
// ^^^ Change this line if you move your application folder

从 4.5.2 开始,如果您不进行任何自定义,您的 index.php 应该是:

<?php

/*
 *---------------------------------------------------------------
 * CHECK PHP VERSION
 *---------------------------------------------------------------
 */

$minPhpVersion = '8.1'; // If you update this, don't forget to update `spark`.
if (version_compare(PHP_VERSION, $minPhpVersion, '<')) {
    $message = sprintf(
        'Your PHP version must be %s or higher to run CodeIgniter. Current version: %s',
        $minPhpVersion,
        PHP_VERSION
    );

    header('HTTP/1.1 503 Service Unavailable.', true, 503);
    echo $message;

    exit(1);
}

/*
 *---------------------------------------------------------------
 * SET THE CURRENT DIRECTORY
 *---------------------------------------------------------------
 */

// Path to the front controller (this file)
define('FCPATH', __DIR__ . DIRECTORY_SEPARATOR);

// Ensure the current directory is pointing to the front controller's directory
if (getcwd() . DIRECTORY_SEPARATOR !== FCPATH) {
    chdir(FCPATH);
}

/*
 *---------------------------------------------------------------
 * BOOTSTRAP THE APPLICATION
 *---------------------------------------------------------------
 * This process sets up the path constants, loads and registers
 * our autoloader, along with Composer's, loads our constants
 * and fires up an environment-specific bootstrapping.
 */

// LOAD OUR PATHS CONFIG FILE
// This is the line that might need to be changed, depending on your folder structure.
require FCPATH . '../app/Config/Paths.php';
// ^^^ Change this line if you move your application folder

$paths = new Config\Paths();

// LOAD THE FRAMEWORK BOOTSTRAP FILE
require $paths->systemDirectory . '/Boot.php';

exit(CodeIgniter\Boot::bootWeb($paths));
© www.soinside.com 2019 - 2024. All rights reserved.