For some reason its saying that both the datetime_sent and sender_avatar properties are undefined. I don't see why this error is saying it when it is clearly with the print_r below.
Code:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: stdClass::$datetime_sent
Filename: models/messages_model.php
Line Number: 72
A PHP Error was encountered
Severity: Notice
Message: Undefined property: stdClass::$sender_avatar
Filename: models/messages_model.php
Line Number: 74
There's a var_dump of an array at the bottom of my code. This is also included next.
PHP Code:
array(4) { [0]=> object(stdClass)#29 (8) { ["message_id"]=> string(1) "1" ["subject"]=> string(12) "Test Message" ["datetime_sent"]=> string(6) "1 week" ["attachments"]=> NULL ["message_content"]=> string(446) "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." ["sender_name"]=> string(16) "Jeffrey Davidson" ["sender_email_address"]=> string(20) "xtremer360@yahoo.com" ["sender_avatar"]=> string(82) "http://dev.kansasout...rs/avatar5.jpg" } [1]=> object(stdClass)#30 (8) { ["message_id"]=> string(1) "2" ["subject"]=> string(18) "Testing PM Message" ["datetime_sent"]=> string(19) "2012-09-22 18:27:25" ["attachments"]=> string(37) "["file1.jpg","file2.jpg","file3.jpg"]" ["message_content"]=> string(51) "This is jsut a test of the personal message system!" ["sender_name"]=> string(11) "Frank Scott" ["sender_email_address"]=> string(24) "frankscott@testemail.com" ["sender_avatar"]=> NULL } [2]=> object(stdClass)#31 (8) { ["message_id"]=> string(1) "3" ["subject"]=> string(16) "Testing Whatever" ["datetime_sent"]=> string(19) "2012-10-04 05:03:09" ["attachments"]=> NULL ["message_content"]=> string(11) "dak;fdaf;ld" ["sender_name"]=> string(11) "Frank Scott" ["sender_email_address"]=> string(24) "frankscott@testemail.com" ["sender_avatar"]=> NULL } [3]=> object(stdClass)#32 (3) { ["attachments"]=> array(3) { [0]=> array(2) { ["file_name"]=> string(9) "file1.jpg" ["is_file"]=> bool(false) } [1]=> array(2) { ["file_name"]=> string(9) "file2.jpg" ["is_file"]=> bool(false) } [2]=> array(2) { ["file_name"]=> string(9) "file3.jpg" ["is_file"]=> bool(false) } } ["datetime_sent"]=> string(8) "42 years" ["sender_avatar"]=> string(81) "http://dev.kansasout...ars/avatar.jpg" } }
PHP Code:
/** * Gets all or last $x number of personal messages of the specified user * * @param integer $user_id User ID of the user specified * @param integer $limit Limit of how many messages to retrieve * @return object/NULL */ public function get_personal_messages($user_id, $limit = NULL, $timezone) { $this->db->select('personal_messages.message_id'); $this->db->select('personal_messages.subject'); $this->db->select('personal_messages.datetime_sent'); $this->db->select('personal_messages.attachments'); $this->db->select('personal_messages.message_content'); $this->db->select('CONCAT(users.first_name, " ", users.last_name) AS sender_name', FALSE); $this->db->select('users.email_address AS sender_email_address'); $this->db->select('user_profiles.user_avatar AS sender_avatar'); $this->db->from('personal_messages'); $this->db->join('users', 'users.user_id = personal_messages.from_user_id'); $this->db->join('user_profiles', 'users.user_id = user_profiles.user_id'); $this->db->where('personal_messages.to_user_id', $user_id); if ($limit != NULL) { if (is_numeric($limit)) { $this->db->limit($limit); } } $query = $this->db->get(); $personal_messages = $query->result(); if (count($personal_messages) > 0) { for ($x = 0; $x < count($personal_messages); $x++) { $attachments = $personal_messages[$x]->attachments; if ($this->functions_model->null_check($attachments) === FALSE) { $attachments = json_decode($attachments, TRUE); for ($x = 0; $x < count($attachments); $x++) { $file_name = $attachments[$x]; if ($this->functions_model->is_file('assets/downloads/'.$file_name, FALSE) === TRUE) { $attachments[$x] = array('file_name' => $file_name, 'is_file' => TRUE); } else { $attachments[$x] = array('file_name' => $file_name, 'is_file' => FALSE); } } $personal_messages[$x]->attachments = $attachments; } $personal_messages[$x]->datetime_sent = $this->functions_model->actual_time('d F Y g:i a', $timezone, strtotime($personal_messages[$x]->datetime_sent)); $avatar = $this->functions_model->site_url().'assets/themes/'.$this->config->item('default_theme').'/images/avatars/avatar.jpg'; if ($this->functions_model->null_check($personal_messages[$x]->sender_avatar) === FALSE) { if ($this->functions_model->is_file('assets/themes/supr/images/avatars/'.$personal_messages[$x]->sender_avatar, FALSE) === TRUE) { $avatar = $this->functions_model->site_url().'assets/themes/'.$this->config->item('default_theme').'/images/avatars/'.$personal_messages[$x]->sender_avatar; } } $personal_messages[$x]->datetime_sent = $this->functions_model->time_since(strtotime($personal_messages[$x]->datetime_sent)); $personal_messages[$x]->sender_avatar = $avatar; } } echo '<pre>'; var_dump($personal_messages); echo '</pre>'; die(); return $personal_messages; }
Last edited by CoolAsCarlito; 10-11-2012 at 07:20 PM..
Something is wrong with this chunk of code because it is throwing attachments in its own first level array. So I need to figure out how I can work with the attatchments correctly to where it will apply the tasks below to each of the items in the first level array.
Wait, you're original post has errors in it though. That's what I was looking for, to determine which one(s) of the records in the iteration threw those errors.
I mean to me it looks like the error is here:
Code:
$personal_messages[$x]->datetime_sent = $this->functions_model->actual_time('d F Y g:i a', $timezone, strtotime($personal_messages[$x]->datetime_sent));
$avatar = $this->functions_model->site_url().'assets/themes/'.$this->config->item('default_theme').'/images/avatars/avatar.jpg';
if ($this->functions_model->null_check($personal_messages[$x]->sender_avatar) === FALSE)
With a stdclass object, you shouldn't be receiving an error whilst writing to a property, only while attempting to retrieve one that hasn't yet been set. Above ::$datetime_sent is used in the strtotime, and ::$sender_avatar is used in null_check.
So what I was hoping to see was the record counter in conjunction with the above errors.
Code:
Evaluating Record: 1
A PHP Error was encountered
Severity: Notice
Message: Undefined property: stdClass::$sender_avatar
Filename: models/messages_model.php
Line Number: 74
The whole code block with the attachments is what's causing the errors because if I comment it out then the array works fine however I still need it to run the null check and also have it run the other tasks.
The whole code block with the attachments is what's causing the errors because if I comment it out then the array works fine however I still need it to run the null check and also have it run the other tasks.
That makes no sense. The error itself isn't related to the use of the attachments, it indicates an issue with the datetime_sent and sender_avatar.
Can you confirm which lines are 72 and 74?
I don't know, it doesn't make sense that is the error you would receive by a block that alters a different property. The only time you should hit an error is if you completely reassign the object itself, or if you read that property, and you don't do either until after that block of code.