在cakephp 2.0.2中使用shell类中的插件组件
我想使用shell类中的插件组件。我正在尝试使用:在cakephp 2.0.2中使用shell类中的插件组件,cakephp,cakephp-2.0,Cakephp,Cakephp 2.0,我想使用shell类中的插件组件。我正在尝试使用: App::import('Component', 'Myplugin.Mycomponent'); $this->Mycomponent =& new MycomponentComponent(); 不幸的是,上述方法似乎失败了 我收到一条错误消息,说找不到组件类 有什么建议我应该如何解决这个问题吗 谢谢您应该首先查看测试用例!通过这种方式,您会发现它们是通过以下方式手动包含的: App::uses('ComponentColl
App::import('Component', 'Myplugin.Mycomponent');
$this->Mycomponent =& new MycomponentComponent();
不幸的是,上述方法似乎失败了
我收到一条错误消息,说找不到组件类
有什么建议我应该如何解决这个问题吗
谢谢您应该首先查看测试用例!通过这种方式,您会发现它们是通过以下方式手动包含的:
App::uses('ComponentCollection', 'Controller');
App::uses('AppleComponent', 'Myplugin.Controller/Component');
及
旁注:
如果您需要在控制器之外的其他地方使用组件,那么您就是做错了!
您应该将功能提取到模型或库中,并从组件和shell调用它您应该首先查看测试用例!通过这种方式,您会发现它们是通过以下方式手动包含的:
App::uses('ComponentCollection', 'Controller');
App::uses('AppleComponent', 'Myplugin.Controller/Component');
及
旁注:
如果您需要在控制器之外的其他地方使用组件,那么您就是做错了!
您应该将功能提取到模型或库中,并从组件和shell调用它我知道这是hella old,但我只是在处理遗留CakePHP 2应用程序时遇到了这个问题 在控制器中:
public $components = array(
'Myplugin.Mycomponent',
);
然后,您可以通过以下方式访问该组件:
$this->Mycomponent->mymethod();
我知道这是hella的老版本,但我只是在处理遗留的CakePHP 2应用程序时遇到了这个问题 在控制器中:
public $components = array(
'Myplugin.Mycomponent',
);
然后,您可以通过以下方式访问该组件:
$this->Mycomponent->mymethod();
谢谢你帮助马克。但是我不确定第二行。我是这样做的:App::使用“PokerAliasesWebService”、“Pluginname.Controller/Component”;你能帮我理解吗?谢谢。sry,我更正了上面的陈述:它是App::uses'PokerAliasesWebServiceComponent',…好的,所以我的代码目前看起来是这样的:App::uses'Component',Controller';应用程序::使用'PokerAliasesWebServiceComponent','Pluginname.Controller/Component'$集合=新组件集合$此->PokerAliasesWebService=新PokerAliasesWebService组件$Collection;但是我得到一个错误,说找不到ComponentCollection类。你知道Pluginname应该是你的插件名,对吗?我相应地编辑了我的文章。嗨,马克,是的,我也试过了,但是我仍然得到ComponentCollection类NotFound错误。谢谢你的帮助马克。但是我不确定第二行。我是这样做的:App::使用“PokerAliasesWebService”、“Pluginname.Controller/Component”;你能帮我理解吗?谢谢。sry,我更正了上面的陈述:它是App::uses'PokerAliasesWebServiceComponent',…好的,所以我的代码目前看起来是这样的:App::uses'Component',Controller';应用程序::使用'PokerAliasesWebServiceComponent','Pluginname.Controller/Component'$集合=新组件集合$此->PokerAliasesWebService=新PokerAliasesWebService组件$Collection;但是我得到一个错误,说找不到ComponentCollection类。你知道Pluginname应该是你的插件名,对吗?我相应地编辑了我的文章。嗨,马克,是的,我也试过了,但是我仍然得到ComponentCollection类NotFound错误。