title: Fatal error: Call to a member function read() on a non-object on LanguageComponent
body: <p>I am having this line in my CakePHP code: <code>$language = $this-&gt;Cookie-&gt;read('language');</code></p>
  
  <p>and I'm getting this error: </p>
  
  <pre><code>Fatal error: Call to a member function read() on a non-object in
  C:\Apache24\htdocs\cake\app\Controller\Component\LanguageComponent.php on line 27
  </code></pre>
  
  <p>Here is my <strong>LanguageComponent.php</strong> code</p>
  
  <pre><code>&lt;?php
  
  //App::Import('Component', 'Cookie'); 
  class LanguageComponent extends Object {
  
      public $controller = null;
      public $components = array('Cookie');
      public $languages = array();
  
      public function initialize($controller) {
          $this-&gt;controller = $controller;
          if (empty($languages)) {
              $this-&gt;languages = Configure::read('Config.languages');
          }
          $this-&gt;set();
      }
  
      public function set($language = null) {
          $saveCookie = false;
          if (empty($language) &amp;&amp; isset($this-&gt;controller)) {
              if (!empty($this-&gt;controller-&gt;params['named']['lang'])) {
                  $language = $this-&gt;controller-&gt;params['named']['lang'];
              } elseif (!empty($this-&gt;controller-&gt;params['url']['lang'])) {
                  $language = $this-&gt;controller-&gt;params['url']['lang'];
              }
              if (!empty($language)) {
                  $saveCookie = true;
              }
          }
          if (empty($language)) {
              $language = $this-&gt;Cookie-&gt;read('language');
              if (empty($language)) {
                  $saveCookie = true;
              }
          }
          if (empty($language) &amp;&amp; !array_key_exists($language, $this-&gt;languages)) {
              $language = Configure::read('Config.language');
          }
          Configure::write('Config.language', $language);
          if ($saveCookie) {
              $this-&gt;Cookie-&gt;write('language', $language, false, '1 year');
          }
      }
  
  }
  
  ?&gt;
  </code></pre>
  
  <p>Where could the problem be?</p>