Yii Framework Forum: Session File And Session Database - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Session File And Session Database Is it possible to use both? Rate Topic: -----

#1 User is offline   zitter 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 140
  • Joined: 14-July 09

Posted 13 October 2012 - 03:03 PM

I would like to use both type of session management in my application: filesystem and database session. So I've add in my protected/config/main.php components section:

            'session' => array(
                        'class'=>'CHttpSession',
                 ),  

              'sessiondb' => array(
                        'class'=>'CDbHttpSession',
                        'connectionID'=>'db',
                              ),


Now, Yii::app()->sessiondb doesn't work, in the sense that it doesn't store data in YiiSession table. Moreover, YiiSession table is not created by default. Even if I create YiiSession table by hand, CDbHttpSession doesn't store data in the table.
I've tried to add some data and print_r out , this is the result:
app()->sessiondb["foo"]="bar";
print_r(app()->sessiondb);

// below, the result:
CDbHttpSession Object
(
    [connectionID] => db
    [sessionTableName] => YiiSession
    [autoCreateSessionTable] => 1
    [_db:CDbHttpSession:private] => 
    [autoStart] => 1
    [behaviors] => Array
        (
        )

    [_initialized:CApplicationComponent:private] => 1
    [_e:CComponent:private] => 
    [_m:CComponent:private] => 
)


If I comment 'session' part of that config, and rename 'sessiondb' in 'session' it works. It seems that you can work only with one type of session, filesystem OR database, not with both... and component must be named 'session' to work.
Any idea?

TIA
Danilo
0

#2 User is offline   Stefano Mtangoo 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 185
  • Joined: 02-January 12
  • Location:Dar es Salaam, Tanzania

Posted 13 October 2012 - 03:13 PM

Why on earth would you need both? :blink:
AFAIK, this is a design issue that should be settled before you upload. If it is secure to store on file then you go for it, else you go for db.

I can't get your logic of using both!
And God said, Let there be science...and it was so!
Training Manager Written in Yii here
0

#3 User is offline   zitter 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 140
  • Joined: 14-July 09

Posted 13 October 2012 - 04:22 PM

OK, let's say I want to decide to use one or other in admin space of my app. I suppose I cannot, right?
0

#4 User is offline   alirz23 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 819
  • Joined: 08-August 12
  • Location:Durban, South Africa

Posted 14 October 2012 - 01:36 AM

I'm not sure if you can or can't but you have some serious design issues or you confused do you even know why do more than one session store
0

#5 User is offline   zitter 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 140
  • Joined: 14-July 09

Posted 14 October 2012 - 02:39 AM

View Postalirz23, on 14 October 2012 - 01:36 AM, said:

I'm not sure if you can or can't but you have some serious design issues or you confused do you even know why do more than one session store


As write above, my first goal is to choose, in the admin page, if you want to save session in filesystem or in database. Is it possible or not?

TIa
Danilo
0

#6 User is offline   Jorgee 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 58
  • Joined: 22-March 13

Posted 30 April 2013 - 10:38 AM

It is possible.

You must declare a variable in top of main.php, say $sessionSystem = 'CDbHttpSession' or 'CHttpSession'. In the config you put 'session'=>array( class=>$sessionSystem, ),
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users