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