title: Server-side function throws a php error when accessed through ajax
body: <p>I am using CodeIgniter-Bonfire for a web application that lets the site administrator verify or unverify a user's "stuff" (like name and work experience). The admin can just choose from a dropdown list "Verify" or "Unverify". When the value of the dropdown list changes, an ajax call is made to the server. The server then echoes out some value to the javascript, which inserts it into the view page. </p>
  
  <p>Everything is working--the database is changed accordingly, the echoed value is correct--but the javascript now also catches an error message from the server-side.</p>
  
  <p>The error is: <code>Trying to get property of non-object.</code></p>
  
  <p>I've done echo's before and after where the errors supposedly occur, but the object prints out just fine. I'm at a loss because this didn't used to happen. </p>
  
  <p>The really annoying thing is that the error seems to happen randomly. It can be when verification goes from verified to unverified and vice versa. Sometimes the error prints out just before the echoed value and sometimes it just disappears of its own accord (but not before being displayed for a split second.</p>
  
  <p>Thank you in advance.</p>
  
  <p>The javascript looks like this: </p>
  
  <pre><code>$(document).on('change', '.verified', function(event) {
      var id = $(this).attr('id');
  $.ajax({
      type: "POST",
      url: 'http://theurl.com/module/controller/verify/100/files/24'
  }).done(function(msg) {
      $('#timestamp_'+id).text(msg);
  });
  </code></pre>
  
  <p>function verify looks like this:</p>
  
  <pre><code>public function verify($user_id, $other_table, $other_id)
  {
      $this-&gt;load-&gt;model('profile/Verifiable_items_model', 'vi_model');
      $item = $this-&gt;vi_model-&gt;find_by(array(
                  'user_id' =&gt; $user_id,
                  'other_table' =&gt; $other_table,
                  'other_id'  =&gt; $other_id
              ));
  
      $update_date = 0;
  
      if ($item-&gt;verified == 0) // ERROR HERE
      {
          $update_date = date('Y-m-d H:i:s', time());
          $data = array('verified' =&gt; 1, 'notes_time' =&gt; date('Y-m-d H:i:s', time()), 'verified_by' =&gt; $this-&gt;current_user-&gt;username);
      }
      else
      {
          $data = array('verified' =&gt; !($item-&gt;verified), 'notes_time' =&gt; NULL); // ERROR HERE
      }
  
      $this-&gt;vi_model-&gt;update($item-&gt;id, $data);
  
      echo $update_date;
  }
  </code></pre>