首页  >  问答  >  正文

错误:“您的应用程序类没有 bootstrap() 方法。请添加一个。”

我最近开始使用 CakePHP 4.X 在本地构建一个应用程序。我安装了 Composer 并使用它成功安装了 CakePHP 身份验证和授权插件。现在,我正在尝试转向一些社区开发的插件,例如

我可以安装所有插件,但是当我尝试加载插件时出现问题。根据每个插件 Git 页面上的说明,我尝试使用以下行从 CLI 加载插件

bin\cake plugin load BootstrapUI

(我使用的是 Windows,因此使用反斜杠)

在所有情况下我都会收到以下消息:

Your Application class does not have a bootstrap() method. Please add one.

我的src/Application.php文件如下所示

class Application extends BaseApplication
public function bootstrap() : void
{
    // Call the parent to `require_once` config/bootstrap.php
    parent::bootstrap();

    if (PHP_SAPI === 'cli') {
        $this->bootstrapCli();
    } else {
        FactoryLocator::add(
            'Table',
            (new TableLocator())->allowFallbackClass(false)
        );
    }

    /*
     * Only try to load DebugKit in development mode
     * Debug Kit should not be installed on a production system
     */
    if (Configure::read('debug')) {
        $this->addPlugin('DebugKit');
    }

    // Load more plugins here
    $this->addPlugin('Authorization');
    $this->addPlugin('Authentication');
    $this->addPlugin('BootstrapUI');
    
}

P粉872182023P粉872182023215 天前366

全部回复(1)我来回复

  • P粉198670603

    P粉1986706032024-02-22 13:17:49

    您的应用程序类在 class Application extends BaseApplication 之后缺少 {,但我猜它在此处粘贴/编辑不正确。

    您的命令似乎有效,因为我看到插件 $this->addPlugin('BootstrapUI') 已添加到文件中。

    执行 CLI 命令时,请确保位于正确的路径(在应用程序的根目录中):

    bin\cake plugin load BootstrapUI

    您可以在 bootstrap() 方法中手动添加插件,无需 CLI。

    回复
    0
  • 取消回复