php version 5.3.1 with codeigniter 2.0.2
help me, i have errors like this :
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object and Invalid argument supplied for foreach()
Filename: controllers/login.php
Line Number: 20
Controller
parent::__construct();
$this->load->model('option_m');
$option = $this->option_m->get_by(array('nama_opsi' => 'store_option'));
foreach (unserialize($option->value_opsi) as $key => $val) {
$this->data->$key = $val;
}
$this->template->use_asset()->set_judul('Form Login')->set_css('login');
$this->data->metadata = $this->template->get_metadata();
$this->data->judul = $this->template->get_judul();
}
in the sublime text, line number 20 is, but im not sure:
foreach (unserialize($option->value_opsi) as $key => $val) {
$this->data->$key = $val;
Try storing unserialize($option->value_opsi)
in an intermediate variable and print it out. I'm betting that's not an array format that foreach can accept.
First verify if $option is valid before using it, otherwise you will end up trying to access values from an invalid return. Suppose your query returned $option = false, then you tried to access a field from it like $option->value, then you will get the same error.
I suggest you to put a if statement before using it:
if($option) { foo; bar; ...}
And use unserialize only if $option->value_opsi is a serialized value.
Hope it helped.