search

Home  >  Q&A  >  body text

Error: "Your application class does not have a bootstrap() method. Please add one."

I recently started building an application locally using CakePHP 4.X. I installed Composer and used it to successfully install the CakePHP authentication and authorization plugin. Now I'm trying to move to some community developed plugins like

I can install all the plugins, but when I try to load the plugins I have a problem. Following the instructions on each plugin's Git page, I tried loading the plugin from the CLI using the following lines

bin\cake plugin load BootstrapUI

(I'm using Windows so I use backslashes)

In all cases I receive the following message:

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

My src/Application.php file looks like this

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粉872182023284 days ago426

reply all(1)I'll reply

  • P粉198670603

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

    Your application class is missing { after the class Application extends BaseApplication, but I guess it was pasted/edited incorrectly here.

    Your command seems to work as I see the plugin $this->addPlugin('BootstrapUI') has been added to the file.

    When executing CLI commands, make sure you are at the correct path (in the root directory of your application):

    bin\cake plugin load BootstrapUI

    You can add plugins manually in bootstrap() method without CLI.

    reply
    0
  • Cancelreply