Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cakephp: using $this->Component->load() in component

I want to add components in an component.

I've found this on the cake

$this->OneTimer = $this->Components->load('OneTimer');
$this->OneTimer->getTime();
(in the fly-mehtod)

But, when I try it in my controller i get the following:

Fatal error: Call to a member function load() on a non-object

What am I doing wrong? Maybe the in the fly-method is only for controllers, and not for components?

Thanks!

like image 448
Bob Avatar asked Oct 26 '25 20:10

Bob


1 Answers

You can just use App::uses to import components in another component

App::uses('OneTimer', 'Controller/Component');
$this->OneTimer = new OneTimerComponent(new ComponentCollection());
$this->OneTimer->getTime();
like image 84
cornelb Avatar answered Oct 29 '25 20:10

cornelb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!