title: Codeigniter Helper function returning error
body: <p>I would like to use the code below as a helper function, since it will be called from several controllers in my app.</p>
  
  <p>As you can see this is a PHP curl to post text to a user's Facebook wall.</p>
  
  <pre><code>} elseif ($this-&gt;input-&gt;post('post_facebook')) { //"post to facebook" checkbox is ticked
  
          $this-&gt;load-&gt;model('facebook_model');
  
          $token = $this-&gt;facebook_model-&gt;get_facebook_cookie();
  
          $attachment =  array(
              'access_token'  =&gt; $token['access_token'],
              'message'       =&gt; $post['posts_text'],
          );
  
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/' . $token['uid'] . '/feed');
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
          curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
          curl_setopt($ch, CURLOPT_POST, true);
          curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  //to suppress the curl output
          $result = curl_exec($ch);
          curl_close($ch);
  </code></pre>
  
  <p>This code works perfectly when inside a controller. But I would like to do something like this instead:</p>
  
  <p>Put this in helpers/functions_helper.php:</p>
  
  <pre><code>function post_facebook_wall($post) {
  
      $this-&gt;load-&gt;model('facebook_model');
  
      $token = $this-&gt;facebook_model-&gt;get_facebook_cookie();
  
      $attachment =  array(
          'access_token'  =&gt; $token['access_token'],
          'message'       =&gt; $post['posts_text'],
      );
  
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/' . $token['uid'] . '/feed');
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
      curl_setopt($ch, CURLOPT_POST, true);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  //to suppress the curl output
      $result = curl_exec($ch);
      curl_close($ch);        }
  </code></pre>
  
  <p>Then in my controller:</p>
  
  <pre><code>...
  } elseif ($this-&gt;input-&gt;post('post_facebook')) { //post to facebook checkbox is ticked
  
      $post = array('posts_text' =&gt; 'sample text');
  
      post_facebook_wall($post);
  
  }
  </code></pre>
  
  <p>Unfortunately this isn't working, and I get a 500 error.</p>
  
  <p><code>functions_helper.php</code> is in autoload.</p>
  
  <p>Any ideas what I'm doing wrong here? Thanks in advance.</p>