cakephp加载组件飞

Ami*_*rma 1 php cakephp

我想在cakePHP中加载组件在此示例中,为json响应动态加载RequestHandler组件

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'));
}
Run Code Online (Sandbox Code Playgroud)

初始化函数生成的错误显示未定义.

修订更清晰的图片:

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'));
}
Run Code Online (Sandbox Code Playgroud)

我也试过了

public function xyz() {

    $this->RequestHandler =  $this->Components->load('RequestHandler');
    $abc = array("hello","world");
    $this->set('abc', $abc);
    $this->set('_serialize', array( 'abc'));
}
Run Code Online (Sandbox Code Playgroud)

我不能使用这样的组件#$ this-> RequestHandler-> getTime(); 因为cakephp自动处理json respone.当我使用http://disecake.localhost/resources/xyz.json点击上面的代码时

{"code":500,"url":"/ resources/xyz.json","name":"查看文件"/var/www/disecake/app/View/Resources/xyz.ctp"缺失."}

我用的时候

public $components = array( 'RequestHandler'); 
在我的cotroller比输出

{"abc":["hello","world"]}

我想现在问题更清楚了.