How to get the parameters of _search form in Yii2

Hi, I am using Yii 2 basic application template.
I have a controller called Ascteacherreport and search model for the same.
I have the CRUD for the above controller. User can create, delete and update the model data.
I have the search form enabled on index page. I need to get the parameters of the search form and pass it to the controller Ascteacherreport action.

_search


<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
use app\models\Asccenter;
use app\models\Ascuser;

/* @var $this yii\web\View */
/* @var $model app\models\AscteacherreportSearch */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="ascteacherreport-search">
<?php $form = ActiveForm::begin([
        'action' => ['index'],
        'method' => 'get',
    ]); ?>
<div class="row">
<div class="col-sm-3">
      <?= $form->field($model, 'ASCId')->dropDownList()?>
</div>
	  <div class="col-sm-3">
	  <?= $form->field($model, 'UserId')->dropDownList()?>
</div>
<div class="col-sm-3">
<?= $form->field($model, 'Year') ?>
</div>
</div>
<div class="form-group">
        <?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
        <?= Html::a('Reset',['index'], ['class' => 'btn btn-default']) ?>
    </div>

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

In the controller, AscteacherreportController()


<?php

namespace app\controllers;
use Yii;
use app\vendor\phpoffice\phpexcel\Classes\PHPExcel;
use app\models\Ascteacherreport;
use app\models\AscteacherreportSearch;
use yii\web\Controller;
class AscteacherreportController extends Controller
{
    /**
     * {@inheritdoc}
     */
    public function behaviors()
    {
    }
   public function actionData() // This action should receive/get the search form parameters
   {
     // load search form model

    $model = new AscteacherreportSearch();
    
    // work with the search form parameters
    echo $model->ASCId." - ".$model->UserId." - ".$model->Year;

   }
}

Parameters are coming into action via GET or POST. Get these from request as usual.

_search.php

 <?php 
   $form = ActiveForm::begin([
        'action' => ['index'],
        'method' => 'get',
    ]); ?>


<?= $form->field($model, 'ASCId') ?>
<?= $form->field($model, 'UserId') ?>
<?= $form->field($model, 'Year') ?>

 <div class="form-group">
        <?= Html::a('Search',['ascteacherreport/data'], ['class' => 'btn btn-primary']) ?>
        <?= Html::a('Reset',['index'], ['class' => 'btn btn-default']) ?>
    </div>

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

AscteacherreportController.php

<?php

namespace app\controllers;
use Yii;
use app\vendor\phpoffice\phpexcel\Classes\PHPExcel;
use app\models\Ascteacherreport;
use app\models\AscteacherreportSearch;
use app\models\Model;
class AscteacherreportController extends Controller
{
 public function behaviors()
 {
  //.. code
 }
// Below action responsible to get the search form parameters
 
public function actionData()
	{
      $model =new AscteacherreportSearch();
	 if( $model->load(Yii::$app->request->post()))
		{
          echo $model->ASCId;
	    }
	}
}

But ASCId is not getting echoed.

Because you are submitting the form via GET but obtaining parameters from POST which is empty.

If I change it to post, still ASCId is not displayed.

It is working correctly as I made changes to the below

 <?php $form = ActiveForm::begin([
        'action' => ['ascteacherreport/data'], // changed the action
        'method' => 'post',
    ]); ?>


<?= Html::submitButton('Search' ,['class' => 'btn btn-primary']) ?>

Declared the model attributes rule as safe