Search code examples
cakephpcakephp-3.7

Plugin cakephp 3.7


How can I map a plugin into the cakephp 3.7, through a remote folder?

after version 3.4 I am no longer able to load a plugin, I looked at the documentation and checked that it had changes already tried using Application :: addplugin (); and Application :: bootstrap (); that were the solutions I found searching, I do not know if I have to do any more procedure or if some other syntax has changed.


Solution

  • From CakePHP documentation:

    The plugin shell allows you to load and unload plugins via the command prompt. If you need help, run:

    bin/cake plugin --help
    

    Loading Plugins

    Via the Load task you are able to load plugins in your config/bootstrap.php. You can do this by running:

    bin/cake plugin load MyPlugin
    

    This will add the following to your src/Application.php:

    // In the bootstrap method add:
    $this->addPlugin('MyPlugin');
    
    // Prior to 3.6, add the following to config/bootstrap.php
    Plugin::load('MyPlugin');
    

    If you need plugin before any method / event in your bootstrap, then use like:

    class Application extends BaseApplication
        {
            /**
             * {@inheritDoc}
             */
            public function bootstrap()
            {
                $this->addPlugin('OAuthServer', ['routes' => true]);
    
                // Call parent to load bootstrap from files.
                parent::bootstrap();
    
                if (PHP_SAPI === 'cli') {
                    try {
                        $this->addPlugin('Bake');
                    } catch (MissingPluginException $e) {
                        // Do not halt if the plugin is missing
                    }
    
                    $this->addPlugin('Migrations');
                }
    
                /*
                 * 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\Plugin::class);
                }
    
                // Other plugins
                $this->addPlugin('BootstrapUI');
                $this->addPlugin('Search');
    

    Read more:

    https://book.cakephp.org/3.0/en/console-and-shells/plugin-shell.html