YII2 - How to get the value of a field from a search form

I am new to Yii2 and MVC, so I think the answer to the question is simple, but could not find the answer from the documentation and tutorials. Therefore, I need to select the record with the corresponding identifier from the database table. So, here are the steps I follow:

1) I created a model (CustomerReport) with a CRUD generator for the corresponding table and added it to the view, where:

use app\models\CustomerReport;

2) On the watch page, I checked it with

$customer_data = CustomerReport::findone(['id' => 2]);

It works fine for me

3) I added a search form to the view:

<?php $form = ActiveForm::begin(['id' => 'customer-report']); ?>
                <?= $form->field($model, 'id') ?>

                <div class="form-group">
                    <?= Html::submitButton('Submit', ['class' => 'btn btn-primary', 'name' => 'contact-button']) ?>
                </div>

            <?php ActiveForm::end(); ?>

But I could not find a way to search by identifier through the form. As far as I understand, I need to specify the value of the search field in

$customer_data = CustomerReport::findone(['id' => VALUE FROM ACTIVE FORM]);
+4
source share
2

, ,

$customer_data = CustomerReport::findone(['id' => $model->id]);
0

, POSTED (, XyzController.php)

if(isset($_POST['CustomerReport']['id'])  // after form get POSTed
    $customer_data = CustomerReport::findone(['id' => $_POST['CustomerReport']['id']]);
0

All Articles