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