Using a plugin component from shell class in cakephp 2.0.2

a 夏天 提交于 2019-12-11 07:57:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!