Setpagestate And Getpagestate Not Working

I have a form page where i am using two model classes and i am using setpagestate to store these values as follows:


$this->setPageState('step2',$_POST['ModelClass1']); 

$model1=new ModelClass1('step2');

$model1->attributes = $_POST['ModelClass1'];


$this->setPageState('step2',$_POST['ModelClass2']); 

$model2=new ModelClass2('step2');

$model2->attributes = $_POST['ModelClass2'];

Now when i am trying to retrieve these values later on the next page to save it,i am able to retrieve the values for the modelclass2 but not modelclass1.




$model1=new ModelClass1('finish');

$model1->attributes = $this->getPageState('step2',$_POST['ModelClass1']);


$model2=new ModelClass2('finish');

$model2->attributes = $this->getPageState('step2',$_POST['ModelClass2']);

When i change the orientation of modelclass1 and modelclass2 during setpagestate, then i am able to retrieve the values of the first modelclass but not second.


$this->setPageState('step2',$_POST['ModelClass2']); 

$model2=new ModelClass2('step2');

$model2->attributes = $_POST['ModelClass2'];


$this->setPageState('step2',$_POST['ModelClass1']); 

$model1=new ModelClass1('step2');

$model1->attributes = $_POST['ModelClass1'];

I am little confused on how to use setpagestate to store values for multiple models.

Thanx in advanceā€¦ :)

Found the way to solve this,by using array to store multiple models values. I am able to retrieve the values. :)


$this->setPageState('step2',array($_POST['ModelClass1'],$_POST['ModelClass2']));


$value= $this->getPageState('step2',array());

Here $value is an array of objects.