问题
I would like to make use of a plugin component from my shell class. I am trying to use:
App::import('Component', 'Myplugin.Mycomponent');
$this->Mycomponent =& new MycomponentComponent();
Unfortunately the above seems to fail.
And I get an error message saying that the Component class could not be found.
Any suggestion how I should tackle this?
Thanks
回答1:
you should always take a look at the test cases first! this way you would have found out that they are manually included this way:
App::uses('ComponentCollection', 'Controller');
App::uses('AppleComponent', 'Myplugin.Controller/Component');
and
$Collection = new ComponentCollection();
$Apple = new AppleComponent($Collection);
sidenote: if you need to use a component somewhere else than a controller than you are doing sth wrong! you should extract the functionality into a model or lib and call it from both the component and the shell
来源:https://stackoverflow.com/questions/10880694/using-a-plugin-component-from-shell-class-in-cakephp-2-0-2