我想使用我的shell类中的插件组件。我正在尝试使用:
App::import('Component', 'Myplugin.Mycomponent');
$this->Mycomponent =& new MycomponentComponent();不幸的是,上面的方法似乎失败了。
我收到一条错误消息,指出找不到组件类。
有什么建议我应该如何解决这个问题吗?
谢谢
发布于 2012-06-04 19:58:24
你应该总是先看一下测试用例!这样,您就会发现它们是以这种方式手动包含的:
App::uses('ComponentCollection', 'Controller');
App::uses('AppleComponent', 'Myplugin.Controller/Component');和
$Collection = new ComponentCollection();
$Apple = new AppleComponent($Collection);旁白:如果你需要在控制器之外的其他地方使用组件,那么你就做错了!您应该将功能提取到模型或库中,并从组件和shell中调用它
发布于 2021-04-16 03:32:56
我知道这很老,但我只是在开发遗留的CakePHP 2应用程序时遇到了这个问题。
在您的控制器中:
public $components = array(
'Myplugin.Mycomponent',
);然后,您可以通过以下方式访问组件:
$this->Mycomponent->mymethod();https://stackoverflow.com/questions/10880694
复制相似问题