title: CakePHP 3 - How to load components
body: <p>In CakePHP 2 you could specify which components to load in the controller by providing a <code>$components</code> property.</p>
  
  <pre><code>class AppController extends Controller
  {
  
      public $components = [
          'RequestHandler',
          'Security'
      ];
  }
  </code></pre>
  
  <p>I notice this still works in CakePHP 3 but that most of the book uses a new method in which you load every component separately:</p>
  
  <pre><code>public function initialize()
  {
      $this-&gt;loadComponent('RequestHandler');
      $this-&gt;loadComponent('Security');
  }
  </code></pre>
  
  <p>Is the <code>$components</code> property provided only for backwards compatibility? I want to do it the correct Cake 3 way, especially if the former method will be deprecated at some point in the future.</p>
  
  <hr>
  
  <p><strong>Are there any differences in functionality between the two methods?</strong></p>
  
  <p>If I try to configure the SecurityComponent like this, it doesn't work and the configuration seems to be completely ignored, even though it's a valid use of the method:</p>
  
  <pre><code>public function initialize()
  {
      $this-&gt;loadComponent('Security', ['blackHoleCallback', 'blackhole']);
  }
  </code></pre>
  
  <p>Instead, I have to make a separate method call in <code>beforeFilter()</code> to set the configuration and get it to actually work:</p>
  
  <pre><code>public function initialize()
  {
      $this-&gt;loadComponent('Security');
  }
  
  public function beforeFilter(Event $event)
  {
      $this-&gt;Security-&gt;config('blackHoleCallback', 'blackhole');
  }
  </code></pre>
  
  <p>However, the old 'Cake 2' way still works fine:</p>
  
  <pre><code>class AppController extends Controller
  {
  
      public $components = [
          'RequestHandler',
          'Security' =&gt; ['blackHoleCallback' =&gt; 'blackhole']
      ];
  }
  </code></pre>