首頁  >  問答  >  主體

錯誤:“您的應用程式類別沒有 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 天前365

全部回覆(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
  • 取消回覆