How to get ID from different controllers Yii2?

7325

123dd.jpg

In the ActiveForm I have model button with Pjax render field after form from the modal button will created. Added a picture for an example. How can I get newly created id (not select added to the database, need to get the id that comes from this form).

I think I need to set get to button, than with ajax catch this and transfer to my Pjax rendered cell

I tried variations, but unsuccessfully, I can’t fully understand how to implement it. Can anyone help with the solution ?


//TwoController

public function actionCreate()

{

    $model = new Formtwo();


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

        if ($model->save()) {

            echo 1;

        //maybe here I must to do query ?

        } else {

            echo 0;

        }

    } else {

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

            'model' => $model,

        ]);

    }

}

Or maybe in _form with ajax…