I want to load component on fly in cakePHP In this example, loading dynamically RequestHandler component for json response
public function xyz() {
$this->components[] ='RequestHandler';
$this->Components->load('RequestHandler');
$this->RequestHandler->initialize($this);
$abc = array("hello","world");
$this->set('abc', $abc);
$this->set('_serialize', array( 'abc'));
}
error generated on initialize function shows undefined.
AMENDMENT FOR MORE CLEAR PICTURE:
public function xyz() {
$this->components[] ='RequestHandler';
$this->RequestHandler = $this->Components->load('RequestHandler');
$this->RequestHandler->initialize($this);
$abc = array("hello","world");
$this->set('abc', $abc);
$this->set('_serialize', array( 'abc'));
}
I also tried
public function xyz() {
$this->RequestHandler = $this->Components->load('RequestHandler');
$abc = array("hello","world");
$this->set('abc', $abc);
$this->set('_serialize', array( 'abc'));
}
I can't use component like this #$this->RequestHandler->getTime(); because cakephp automatic handle json respone. When I hit just above code using http://disecake.localhost/resources/xyz.json
{"code":500,"url":"/resources/xyz.json","name":"View file " /var/www/disecake/app/View/Resources/xyz.ctp" is missing."}
When I use
public $components = array( 'RequestHandler');in my cotroller than output
{"abc":["hello","world"]}
I think now question is more clear.