本文介绍了在cakephp 2.0.2中使用来自shell类的插件组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的shell类使用一个插件组件。我试图使用:

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.

我收到一条错误消息,说找不到Component类。

And I get an error message saying that the Component class could not be found.

任何建议我应该如何解决这个问题?

Any suggestion how I should tackle this?

谢谢

推荐答案

你应该总是先看看测试用例!这种方式你会发现他们是手动包括这种方式:

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');

$Collection = new ComponentCollection();
$Apple = new AppleComponent($Collection);

sidenote:
如果您需要使用控制器以外的组件做sth错!
您应该将功能提取到模型或lib中,并从组件和shell调用它

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

这篇关于在cakephp 2.0.2中使用来自shell类的插件组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 14:48