LoginSignup
1
1

More than 5 years have passed since last update.

[CakePHP3] Plugin::loadAll()でdebug_kitが動かないとき

Last updated at Posted at 2015-09-15

CakePHP3のPlugin::loadAll()でちょっぴりはまった備忘録

Plugin::load

 Plugin::load('DebugKit');

これじゃあ、debug_kitは動かない

 Plugin::load('DebugKit', ['bootstrap' => true]);

これだと動く
第二引数で明示的にDebugKitのbootstrapを読み込むようにしないといけない模様

Plugin::loadAll

 Plugin::loadAll();

これじゃあ、debug_kitは動かない
全部読み込んでるんじゃないんかい。bootstrap読み込まないけんのか。

 Plugin::loadAll(['bootstrap' => true]);

これでも動かない。おとなしくコアを読んでみる。

    public static function loadAll(array $options = [])
    {
        static::_loadConfig();
        $plugins = [];
        foreach (App::path('Plugin') as $path) {
            if (!is_dir($path)) {
                continue;
            }
            $dir = new DirectoryIterator($path);
            foreach ($dir as $path) {
                if ($path->isDir() && !$path->isDot()) {
                    $plugins[] = $path->getBaseName();
                }
            }
        }
        if (Configure::check('plugins')) {
            $plugins = array_merge($plugins, array_keys(Configure::read('plugins')));
            $plugins = array_unique($plugins);
        }

        foreach ($plugins as $p) {
            $opts = isset($options[$p]) ? $options[$p] : null;
            if ($opts === null && isset($options[0])) {
                $opts = $options[0];
            }
            if (isset(static::$_plugins[$p])) {
                continue;
            }
            static::load($p, (array)$opts);
        }
    }

なるほど、じゃあこれで。

Plugin::loadAll([
    'DebugKit'=>['bootstrap' => true]
]);

動いた。
ちゃんと明示的に宣言しなきゃ駄目みたい。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1