Yii2 Multiple Instances Of The Same Model

I want to get multiplie instance of the same model in my controller. I saw this wiki for Yii 1.1 and tried like that but in my code only last instance in form was acceble from controller my code is here (I commented code with error and variable values):


$model = new Person(['scenario' => 'create_update']);

$contractDate = new DatePart(); // DatePart is my own class

$contractExpirationDate = new DatePart(); // DatePart is my own class


if ($model->load(Yii::$app->request->post()) &&

    $contractDate->load(Yii::$app->request->post()) &&

    $contractExpirationDate->load(Yii::$app->request->post())){


    Yii::info(Yii::$app->request->post(),'test'); // only one instance of Person and one instance of DatePart are available here

    Yii::info($_POST['DatePart'],'test'); // only last instance of DatePart (contractExpirationDate in html form) is available here

    Yii::info($_POST['DatePart'][0],'test'); // Error: Undefined offset: 0

    Yii::info($_POST['DatePart'][1],'test'); // Error: Undefined offset: 1


    $model->save();

    return $this->redirect(['view', 'id' => $model->id]);

} else {

    return $this->render('create', [

        'model' => $model,

        'contractDate' => $contractDate,

        'contractExpirationDate' => $contractExpirationDate,

    ]);

}

It is log result for: Yii::info(Yii::$app->request->post(),‘test’) in debugger as you seen only last DatePart available but I have two DatePart model instance (contractDate and contractExpirationDate):


[

    '_csrf' => 'Vl81R0ZvMk1hD1oELT9aDzkIe3EPHFgiIBJTBhA9RD8GbFM.AhlVBw==',

    'Person' => [

        'name' => 'test name',

        'family' => 'test family',

        'mobile' => '09121212123',

    ],

    'DatePart' => [

        'year' => '2015',

        'month' => 'Jun',

        'day' => 'Mon',

    ],

]

I ask same question on stackoverflow HERE and someone gave me a solution but I got this error:

Call to a member function formName() on a non-object

I think that Model::loadMultiple() not work correctly.