I am working with a configuration file that I created to store users. This, of course, is not what was intended for configurations, but it is a very small application, and I think that would be a good solution.
My array looks like this:
$config['users'] = array(array('username' => 'username', 'password' => 'password'));
It works well. I can quickly and easily get information. BUT, if I try to write a new array (new user) to the configuration file, I get this error: Invalid offset type in isset or empty
I use $this->config->item('users', array('username' =>....)) which does not support arrays.
How can I write arrays to my configuration variable? Is there another way?
EDIT: Well, the bug is fixed thanks to the answer provided by phirschy. I was so sure in my head that I could use config-> item () that I did not check the manual for config-> set_item () ... BUT, it still doesn't work. Here is the specific code:
$users = $this->config->item('users'); array_push($users, array('username' => $this->input->post('username'), 'password' => $this->input->post('password'))); $this->config->set_item('users', json_encode($users)); echo json_encode($users);
This code is called through Ajax, and I have a warning window to see if the values ββare correct. They are. And, as you can see, I tried to save it as json instead of an array ... but this does not work either. Help me please?
Thank you
php codeigniter
CE
source share