Working in CI 2.1.0 and getting a “Call to a member function set() on a non-object…” error with the code excerpt looping through the array below. Seemingly it’s an array of all strings so I’m having trouble seeing why it seems to fail in the middle.
Any insights as to what’s going on would be great. Researched other questions on this error, but still at a loss.
Code excerpt:
foreach($data['jobs'] as $job)
{
foreach($job as $key=>$value){
$job->set($key,$value);
}
}
$data[‘jobs’] array:
Array ( [0] => Array ( [job_id] => 149 [company] => Minnesota Life Insurance [location] => Barrington, IL [start_date] => March '98 [end_date] => June '98 [description] =>
Primary responsibility was research and design of sales and training presentations.
Responsible for scheduling a three person sales and training staff.
[title] => Administrative Secretary [resume_id] => 96 [order_id] => 0 [profile_id] => 38 [user_id] => 1 [vanity_name] => Sample of Template 3 [template_id] => 3 [date_add] => 0000-00-00 00:00:00 [date_mod] => 2012-03-04 11:00:05 ) [1] => Array ( [job_id] => 150 [company] => Manpower Temporary Services [location] => Naperville, IL [start_date] => Dec' 04 [end_date] => June '98 [description] =>
Assigned to GE Silicones in the industrial sales division.
Responsible for analysis of monthly, weekly, and, daily sales reports.
Responsible for scheduling training classes, seminars, and conferences
[title] => Independent Contractor [resume_id] => 96 [order_id] => 1 [profile_id] => 38 [user_id] => 1 [vanity_name] => Sample of Template 3 [template_id] => 3 [date_add] => 0000-00-00 00:00:00 [date_mod] => 2012-03-04 11:00:05 ) [2] => Array ( [job_id] => 151 [company] => KSMR Radio 92.5/94.3FM [location] => Winona, MN [start_date] => May '96 [end_date] => May '97 [description] =>
In charge of a 36 member staff, as well as a 7 member management team, with duties that include disciplinary actions, budgeting, special requests, program scheduling, and hiring.
Balancing a $15,000 dollar budget, as well as chairing a committee to receive a grant for increasing station amenities such as wattage, equipment, space, and music library.
[title] => General Manager [resume_id] => 96 [order_id] => 2 [profile_id] => 38 [user_id] => 1 [vanity_name] => Sample of Template 3 [template_id] => 3 [date_add] => 0000-00-00 00:00:00 [date_mod] => 2012-03-04 11:00:05 ) )
It’s because $job isn’t a class, thats why your getting the ‘call to a member function set() on a non-object‘ – $job is an array. You have to access it like the following.
Maybe you want to transfer the values of $job into a class?