What is best way to get and unserialize data in codeigniter? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6) +--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forumdisplay.php?fid=17) +--- Thread: What is best way to get and unserialize data in codeigniter? (/showthread.php?tid=62273) |
What is best way to get and unserialize data in codeigniter? - wolfgang1983 - 06-27-2015 On my controller I need to be able to get some serialized data but keep on getting error below A PHP Error was encountered Severity: Notice Message: Undefined offset: 0 Filename: common/Dashboard.php Line Number: 40 Backtrace: Var dump string(111) "a:3:{s:7:"user_id";s:2:"20";s:8:"username";s:20:"demo";s:4:"name";s:20:"John Doe";}" PHP Code: $results = $this->get_user_activities(); Model Function PHP Code: public function get_user_activities() { How come there is a offset error? And how can I fix it? RE: What is best way to get and unserialize data in codeigniter? - wolfgang1983 - 06-27-2015 I am just confused on the best way I tried this code below for getting seems to work but not sure if safe PHP Code: $key = unserialize($result['data']); PHP Code: foreach ($results as $result) { RE: What is best way to get and unserialize data in codeigniter? - Wouter60 - 06-27-2015 (06-27-2015, 04:38 AM)riwakawd Wrote: How come there is a offset error? And how can I fix it? Your array $var doesn't have a key called 0. echo $var['user_id']; should give you the userid you're looking for. |