Reputation: 4084
How to use Set function inside components in cake php especially in cake version 1.3 ?
class DevicesComponent extends Object
{
function startup($controller)
{
$this->controller = $controller;
}
function push()
{
$this->set('data', $data);
$this->controller->set('data', $data);
}
}
I am getting the following error Fatal error: Call to undefined method DevicesComponent::set() .
I checked the existing same questions but the links not available 'Set' in Components of Cake PHP
Upvotes: 1
Views: 1500
Reputation: 519
Try this code,it may works..
function startup(&$controller)
{
$this->controller = $controller;
}
And in the push function
function push()
{
$this->controller->set('data', $data);
}
Upvotes: 0
Reputation: 41605
Try it removing the $this->set('data', $data)
from your push
function:
function push()
{
$this->controller->set('data', $data);
}
And using this instead of the startup
function:
public function initialize(){
$this->controller =& $controller;
}
Upvotes: 1
Reputation: 8100
Just remove the line $this->set('data', $data);
and the error will be gone. You already have the correct statement in next line to set view var through the controller instance $this->controller->set('data', $data);
.
Upvotes: 0