Tuesday, September 24, 2013

Plugin after load

Hello,
Can I use (and how) Events System or Dispatcher Filters with my plugins to load method from this plugin after the plugin is loaded? Something like afterLoad -> call -> method.
I have plugin Settings with controller Settings with method hookup which returns array with site settings. How can I load the array from hookup method after the plugin is loaded.

Now Im doing this, this way:

app/Config/bootstrap.php
CakePlugin::load('Settings', array('bootstrap' => true, 'routes' => false));

app/Plugin/Settings/Config/bootstrap.php
Cache::config('settings', array(
    'engine' => 'File',
    'duration' => '+1 week',
    'probability' => 100,
    'path' => CACHE . 'settings' . DS,
));
Configure::load('Settings.config');

app/Plugin/Settings/Config/config.php
App::uses('SettingsController', 'Settings.Controller');
$config = SettingsController::hookup();

app/Plugin/Settings/Controller/SettingsController.php
    public static function hookup() {
        $settings = Cache::read('settings', 'settings');
        if (!$settings) {
            foreach (ClassRegistry::init('Setting')->find('all') as $setting) {
                $settings[$setting['Setting']['key']] = $setting['Setting']['value'];
            }
            Cache::write('settings', $settings, 'settings');
        }
        return $settings;
    }

Is there better way to do this ? To call a method after the plugin is loaded, should I do it in a bootstrap using App::uses and a static method from this plugin ?

Thanks for your help



--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: