For my scenario:
There are two applications:
Application one(app_one) is holding in Yiiframework,which are four roles under protect/modules,they are A,B,C,D. Users and Visitors via webapp access to B,C,D.
Application two(app_two) is outside of Yiiframework.
Both applications deploy in the same webserver.
A->admin;
B->subadmin(it always keeping connect with D);
C->user(user via app_two to visit and redirect to C);
D->visitor(visitor via app_two to communicate with
;
are possible to make visitor via app_two keeping connect with B,with generating session[visitor-B],and user via app_two login/register and redirect to C, with generating sessions[user-C] work together?
It is not needed to have 2 diffent session objects, one is sufficient.
Your first file, your session model, locate it at components:
<?php
class MyAppSession {
public $appid;
public $var1;
public $var2;
public $var3;
}
Your own session manager, locate it at components too:
<?php
class MyMultiSessionManager {
/*
this method will init the array in lazy way
always returning an array of: MyAppSession
*/
public static function init() {
$s = new CHttpSession();
$s->open();
$data = $s['mymultisession'];
// check for null or another invalid values here
if( $data == null ) {
// Lazy init:
$ar = array();
$ar[0] = new MyAppSession(); // for app 1
$ar[1] = new MyAppSession(); // for app 2
$s['mymultisession'] = $ar;
}
$s->close();
return $data;
}
// appid must match the array keys setted on init() , 0 and 1 or anything you like
//
public static function getSession($appid) {
$ar = self::init(); // lazy initializacion called
// dont forget to verify if $appid is in array keys, or it will be crash your app
return $ar[$appid];
}
public static function save($index, $app) {
$ar = self::init();
$ar[$index] = $app;
$s = new CHttpSession();
$s->open();
$s['mymultisession'] = $ar;
$s->close();
}
}
Your testers, action based, put this two test actions in any place you like and runs it
public function actionTestSet($a=1,$b=2)
{
// get the current objects
$app0 = MyMultiSessionManager::getSession(0);
$app1 = MyMultiSessionManager::getSession(1);
// set values
$app0->var1 = "this value must persist for app: ".$a;
$app1->var1 = "this value must persist for app: ".$b;
// save back to session
MyMultiSessionManager::save(0,$app0);
MyMultiSessionManager::save(1,$app1);
$this->renderText('app values setted to '.$a.' and '.$b.' try action TestGet');
}
public function actionTestGet()
{
$app0 = MyMultiSessionManager::getSession(0);
$app1 = MyMultiSessionManager::getSession(1);
$this->renderText("stored values are: ".$app0->var1." and ".$app1->var1);
}
[b]AS YOU CAN SEE IN THE CODE ABOVE, ONLY ONE VAR SESSION IS USED: "mymultisession", FOR THE ENTIRE APPLICATION, AND STORING MULTIPLE VARS FOR DIFFERENT APPLICATIONS, USING THE SAME MODEL,
AND MANAGED BY YOU MULTI SESSION MANAGER CLASS.[/b]