Hi :)

why is it not possible to load cake plugins outside of bootstrap.php?
I want to implement a "plugin management" where all "installed"
plugins saved in database with some configurations of the plugins,
e.g. has a bootstrap or a routes file. Now I want to load the plugins
in AppController::beforeFilter:
========= >8 =========
public function beforeFilter() {
  parent::beforeFilter();

  $this->loadModel( 'PluginHook' );
  $pluginHooks = $this->PluginHook->find(
    'all'
  );
  $plugins = array( );
  foreach ( $pluginHooks as $pluginHook ) {
    $plugins[ $pluginHook[ 'PluginHook' ][ 'hook_id' ] ] =
$pluginHook[ 'Plugin' ];
    foreach ( $pluginHook[ 'Plugin' ] as $plugin ) {
      CakePlugin::load( $plugin[ 'name' ], array( 'bootstrap' =>
( $plugin[ 'has_bootstrap' ] == 1 ), 'routes' =>
( $plugin[ 'has_routes' ] == 1 ) ) );
    }
  }

  $this->set( compact( 'plugins' ) );
}
========= 8< =========

Until this point there is no error message or anything! And now I want
to "run" the plugin in my views:
========= >8 =========
if ( isset( $plugins ) && isset( $plugins[ $hookId ] ) && !
empty( $plugins[ $hookId ] ) ) :
  foreach ( $plugins[ $hookId ] as $plugin ) :
    $url = array(
      'plugin' => strtolower( $plugin[ 'name' ] ),
      'controller' => strtolower( $plugin[ 'start_controller' ] )
    );
    if ( !empty( $plugin[ 'start_action' ] ) ) :
      $url[ 'action' ] = $plugin[ 'start_action' ];
    endif;
    echo $this->requestAction( $url, array( 'return' ) );
  endforeach;
endif;
========= 8< =========

There is nothing to see in the view but in the error.log I get this:
========= >8 =========
2012-01-05 17:13:15 Error: [MissingControllerException] Controller
class SampleController could not be found.
#0 D:\xampp\htdocs\bc\cake-2.0\Cake\Core\Object.php(102): Dispatcher-
>dispatch(Object(CakeRequest), Object(CakeResponse), Array)
#1 D:\xampp\htdocs\bc\apps\sandbox\View\Elements\plugin_hook.ctp(12):
Object->requestAction(Array, Array)
#2 D:\xampp\htdocs\bc\cake-2.0\Cake\View\View.php(598): include('D:
\xampp\htdocs...')
#3 D:\xampp\htdocs\bc\cake-2.0\Cake\View\View.php(320): View-
>_render('D:\xampp\htdocs...', Array)
#4 D:\xampp\htdocs\bc\apps\sandbox\View\Layouts\default.ctp(68): View-
>element('plugin_hook', Array)
#5 D:\xampp\htdocs\bc\cake-2.0\Cake\View\View.php(598): include('D:
\xampp\htdocs...')
#6 D:\xampp\htdocs\bc\cake-2.0\Cake\View\View.php(414): View-
>_render('D:\xampp\htdocs...')
#7 D:\xampp\htdocs\bc\cake-2.0\Cake\View\View.php(376): View-
>renderLayout('<h2>Home</h2>??...', 'default')
#8 D:\xampp\htdocs\bc\cake-2.0\Cake\Controller\Controller.php(900):
View->render('home', NULL)
#9 D:\xampp\htdocs\bc\apps\sandbox\Controller\PagesController.php(28):
Controller->render('home')
#10 [internal function]: PagesController->display('home')
#11 D:\xampp\htdocs\bc\cake-2.0\Cake\Controller\Controller.php(473):
ReflectionMethod->invokeArgs(Object(PagesController), Array)
#12 D:\xampp\htdocs\bc\cake-2.0\Cake\Routing\Dispatcher.php(107):
Controller->invokeAction(Object(CakeRequest))
#13 D:\xampp\htdocs\bc\cake-2.0\Cake\Routing\Dispatcher.php(89):
Dispatcher->_invoke(Object(PagesController), Object(CakeRequest),
Object(CakeResponse))
#14 D:\xampp\htdocs\bc\apps\sandbox\webroot\index.php(97): Dispatcher-
>dispatch(Object(CakeRequest), Object(CakeResponse))
#15 {main}
========= 8< =========

It seems the plugin was not loaded ... For the sake of completenes,
I'm using Cake 2.0.4, the plugin is called 'Sample' and when I just
put the CakePlugin::load portion in the bootstrap.php all is working
fine and as expected:
========= >8 =========
CakePlugin::load( array(
  'Sample' => array( 'bootstrap' => true, 'routes' => true )
) );
========= 8< =========

I hope someone can help me or can explain why its not possible to load
plugins another way than bootstrap.php?

Best wishes for the new year! ;)
-- Christian

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to