我最近開(kāi)始使用 CakePHP 4.X 在本地構(gòu)建一個(gè)應(yīng)用程序。我安裝了 Composer 并使用它成功安裝了 CakePHP 身份驗(yàn)證和授權(quán)插件?,F(xiàn)在,我正在嘗試轉(zhuǎn)向一些社區(qū)開(kāi)發(fā)的插件,例如
我可以安裝所有插件,但是當(dāng)我嘗試加載插件時(shí)出現(xiàn)問(wèn)題。根據(jù)每個(gè)插件 Git 頁(yè)面上的說(shuō)明,我嘗試使用以下行從 CLI 加載插件
bin\cake plugin load BootstrapUI
(我使用的是 Windows,因此使用反斜杠)
在所有情況下我都會(huì)收到以下消息:
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'); }
您的應(yīng)用程序類(lèi)在 class Application extends BaseApplication
之后缺少 {
,但我猜它在此處粘貼/編輯不正確。
您的命令似乎有效,因?yàn)槲铱吹讲寮?$this->addPlugin('BootstrapUI')
已添加到文件中。
執(zhí)行 CLI 命令時(shí),請(qǐng)確保位于正確的路徑(在應(yīng)用程序的根目錄中):
bin\cake plugin load BootstrapUI
您可以在 bootstrap() 方法中手動(dòng)添加插件,無(wú)需 CLI。