CDbHttpSession

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?

The component ID should be 'session' instead of 'dbSession'.

What other problem did you encounter?



	// 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).

Thanks. Bug fixed.

updated to 181 but the behaviour is the same.

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

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.

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

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'];


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?

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();