Welcome Guest, Not a member yet? Register   Sign In
cannot set an index of a session
#1

Hello. I try to change an index of a session but codeigniter sent an Error :

PHP Code:
$this->session->user['coins'] = 5


Code:
Indirect modification of overloaded property CI_Session::$user has no effect

But I didn't send any Error with following code:

PHP Code:
$_SESSION['user']['coins'] = 5


Is there any solution?
Reply
#2

You need to read the CodeIgniter User's Guide

PHP Code:
$this->session->set_userdata('coins''5'); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(07-04-2018, 03:44 AM)InsiteFX Wrote: You need to read the CodeIgniter User's Guide

PHP Code:
$this->session->set_userdata('coins''5'); 

No, This is my session:
PHP Code:
array( 
 
  "user" => array ("coins" => 5


I want to change user coins.
Reply
#4

(07-04-2018, 06:36 AM)hamidb80 Wrote:
(07-04-2018, 03:44 AM)InsiteFX Wrote: You need to read the CodeIgniter User's Guide

PHP Code:
$this->session->set_userdata('coins''5'); 

No, This is my session:
PHP Code:
array( 
 
  "user" => array ("coins" => 5


I want to change user coins.

https://www.codeigniter.com/user_guide/l...ssion-data
Reply
#5

(This post was last modified: 07-04-2018, 03:13 PM by dave friend.)

(07-04-2018, 01:31 AM)hamidb80 Wrote: Hello. I try to change an index of a session but codeigniter sent an Error :

PHP Code:
$this->session->user['coins'] = 5


Code:
Indirect modification of overloaded property CI_Session::$user has no effect

But I didn't send any Error with following code:

PHP Code:
$_SESSION['user']['coins'] = 5

Is there any solution?

I think what you were trying to do is

PHP Code:
$this->session->user = ['coins' => 5]; 

Which produces the exact same result as

PHP Code:
$_SESSION['user']['coins'] = 5

After either of the above is run
PHP Code:
var_dump($_SESSION); 
produces


Code:
array (size=2)
 '__ci_last_regenerate' => int blah-blah-blah
 'user' =>
     array (size=1)
       'coins' => int 5
Reply




Theme © iAndrew 2016 - Forum software by © MyBB