Yii Framework Forum: CDbHttpSession - Yii Framework Forum

Jump to content

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

CDbHttpSession Rate Topic: -----

#1 User is offline   ilzale 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 113
  • Joined: 08-October 08

Posted 09 November 2008 - 02:29 PM

i try to use CDbHttpSession to store something so i configure the main.php file as

// application components
'components'=>array(
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
),
// uncomment the following to set up database
'db'=>array(
'connectionString'=>'mysql:host=localhost;dbname=mambo;',
'username'=>'root',
'password'=>'root',
),
'dbSession'=>array(
'class'=>'CDbHttpSession',
'connectionID'=>'db',
'sessionTableName'=>'test',
)
),


note that db component is the same that i use for the database of the application and it works. the table "prova" is not created (i don't create it because i don't know which fields it needs). so i try to use the default sqlite doing

// application components
'components'=>array(
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
),
// uncomment the following to set up database
'db'=>array(
'connectionString'=>'mysql:host=localhost;dbname=mambo;',
'username'=>'root',
'password'=>'root',
),
'dbSession'=>array(
'class'=>'CDbHttpSession',
)
),



the variables are created in the standard HttpSession, i'm sure because i try to print_r($_SESSION) i find my variables.

why?

0

#2 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,879
  • Joined: 04-October 08
  • Location:DC, USA

Posted 09 November 2008 - 02:47 PM

The component ID should be 'session' instead of 'dbSession'.
What other problem did you encounter?
0

#3 User is offline   ilzale 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 113
  • Joined: 08-October 08

Posted 09 November 2008 - 03:44 PM


// application components
'components'=>array(
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
),
// uncomment the following to set up database
'db'=>array(
'connectionString'=>'mysql:host=localhost;dbname=mambo;',
'username'=>'root',
'password'=>'root',
),
'session'=>array(
'class'=>'CDbHttpSession',
)
),


i changed the main.php like above but i always find the variables in the $_SESSION and in runtime nothing is created (I imagine i should find a folder or a file..).

to save something in the component i do for example:

Yii::app()->session->add('projectId',$_GET['id']);

where session is the id of the component, (before it was dbSession).
0

#4 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,879
  • Joined: 04-October 08
  • Location:DC, USA

Posted 09 November 2008 - 04:04 PM

Thanks. Bug fixed.
0

#5 User is offline   ilzale 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 113
  • Joined: 08-October 08

Posted 09 November 2008 - 04:39 PM

updated to 181 but the behaviour is the same.

i find the variables in $_SESSION, instead of finding a db in runtime.
0

#6 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,879
  • Joined: 04-October 08
  • Location:DC, USA

Posted 09 November 2008 - 05:29 PM

You should be able to find a file named as "session-1.0rc.db" under runtime. I just tested this with the sample yiic webapp.
0

#7 User is offline   ilzale 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 113
  • Joined: 08-October 08

Posted 10 November 2008 - 04:25 AM

can you post main.php modified to use db session and the test you have done?
0

#8 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,879
  • Joined: 04-October 08
  • Location:DC, USA

Posted 10 November 2008 - 08:12 AM

In main.php, added the following:

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


In SiteController::actionIndex(), added the following:

Yii::app()->session->add('test',1);
// echo Yii::app()->session['test'];

0

#9 User is offline   ilzale 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 113
  • Joined: 08-October 08

Posted 10 November 2008 - 01:48 PM

this is the problem:

in my main.php:

<?php

// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'Mambo yii based',
'language'=>Yii::app()->session->itemAt('applicationLanguage'),

// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',
'system.cli.commands.shell.*',
),

// application components
'components'=>array(
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
),
// uncomment the following to set up database
'db'=>array(
'connectionString'=>'mysql:host=localhost;dbname=mambo;',
'username'=>'root',
'password'=>'root',
),
'session'=>array(
'class'=>'CDbHttpSession',
),
),
);

as you can see I set the language of the application looking to a session variable, probably it initialize the dafault session and continue to use the default one instead of initialize the db session. I tried to put the language row after the components but nothing changes.

is it something that should be fixed by you?


0

#10 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,879
  • Joined: 04-October 08
  • Location:DC, USA

Posted 10 November 2008 - 02:19 PM

Yes, that's the cause of the issue. The session is started before the whole configuration is applied to the application.

You can fix this by doing the following in your entry script:

$app=Yii::createWebApplication($configFile);
$app->language=$app->session['applicationLanguage'];
$app->run();

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