Using a plugin component from shell class in cakep

2019-08-01 19:20发布

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条回答
淡お忘
2楼-- · 2019-08-01 19:52

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

查看更多
登录 后发表回答