我想在组件中添加组件。
我在蛋糕上发现了这个
$this->OneTimer = $this->Components->load('OneTimer');
$this->OneTimer->getTime();
(in the fly-mehtod)
但是,当我在 Controller 中尝试时,我得到以下结果:
Fatal error: Call to a member function load() on a non-object
我做错了什么?也许飞行方法仅适用于 Controller ,而不适用于组件?
谢谢!
最佳答案
您可以使用 App::uses
导入另一个组件中的组件
App::uses('OneTimer', 'Controller/Component');
$this->OneTimer = new OneTimerComponent(new ComponentCollection());
$this->OneTimer->getTime();
关于Cakephp:在组件中使用 $this->Component->load(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22069811/