Welcome Guest, Not a member yet? Register   Sign In
Error: Trying to get property of non-object
#2

[eluser]Tim Brownlaw[/eluser]
To make this more generic, it's a good idea to not hardcode the submit_time's source!
So I'd be passing it as a parameter. You might want to change where it comes from later...

Then before you call it, in this case the $submit_time is coming from $this->uri->segment(3), I'd be validating $this->uri->segment(3) exists and is the correct format / data type.

To be even more strict, I'd also be ensuring that $submit_time is indeed the correct format inside the function itself and maybe throwing an exception or return something to indicate it got "bad data". (which I've not included in the code below... that's something for you to look up!)

Code:
function getSent($submit_time) {
  $this->db->where('submit_time', $submit_time);
  $tempsent = $this->db->get('0_request_details');        
  if($tempsent !== FALSE AND $tempsent->num_rows() > 0) { // Did we get a valid result?
    $sent = $tempsent->row();
    $data['sent'] = $sent->is_sent;
  }
  else {  
   $data['sent'] = 0; // No Result found so return the default!
  }
  return $data;
}

So if you don't get a result back - you will get $data['sent'] = 0.


Messages In This Thread
Error: Trying to get property of non-object - by El Forum - 10-22-2014, 12:45 PM
Error: Trying to get property of non-object - by El Forum - 10-23-2014, 08:33 AM



Theme © iAndrew 2016 - Forum software by © MyBB