how is it possible to pass data in between two models.
i have model called Search and Activity.
after a logic happen in Search i need a value to be stored in a session and after words when i access the session via Activity model i should get that stored value in session.
$activities = Activity::model()->findAll($criteria);
foreach ($activities as $val)
$matchingActs[] = $val->id;
i added it the below way (creating session) Search Model
Yii::app()->session['ActivitiesId'] = $matchingActs;
used it in Activity as following..
print_r(Yii::app()->session['ActivitiesId']); exit();
this doesnt work and i am thinking weather i should use getState and setState.
confused with two models data passing
OUTPUT is as below..
Array ( [0] => 2 [1] => 9 [2] => 3 [3] => 16 [4] => 8 [5] => 5 [6] => 4 [7] => 11 [8] => 1 [9] => 10 [10] => 13 [11] => 15 [12] => 14 [13] => 7 [14] => 17 [15] => 18 [16] => 12 [17] => 6 [18] => 19 [19] => 24 [20] => 25 )
but actually insert only this array.. but something else as above only comes up.
Array ( [0] => 24 [1] => 25 ) // $matchingActs
EDIT 1
Used setState and getState but still its outputting the same. i am confused why this strange behavior from yii
var_dump results are below inside SEARCH model.. // var_dump($matchingActs);
array (size=2)
0 => string '24' (length=2)
1 => string '25' (length=2)
//Yii::app()->user->setState('globalunit',$matchingActs);
array (size=2) // var_dump(Yii::app()->user->getState('globalunit'));
0 => string '24' (length=2)
1 => string '25' (length=2)
Now in Activity if i do the same, // var_dump(Yii::app()->user->getState('globalunit'));
array (size=21)
0 => string '2' (length=1)
1 => string '9' (length=1)
2 => string '3' (length=1)
3 => string '16' (length=2)
4 => string '8' (length=1)
5 => string '5' (length=1)
6 => string '4' (length=1)
7 => string '11' (length=2)
8 => string '1' (length=1)
9 => string '10' (length=2)
10 => string '13' (length=2)
11 => string '15' (length=2)
12 => string '14' (length=2)
13 => string '7' (length=1)
14 => string '17' (length=2)
15 => string '18' (length=2)
16 => string '12' (length=2)
17 => string '6' (length=1)
18 => string '19' (length=2)
19 => string '24' (length=2)
20 => string '25' (length=2)