Your Form need the $searchModel
from somewhere.
in order to render the form so you have to pass it to your view like your filter does
public function actionIndex()
{
$query = Books::find();
list($books, $pagination) = $this->actionPagination($query);
$searchModel = new Books();
return $this->render('index', [
'books' => $books,
'pagination' => $pagination,
'totalPages' => max(1, ceil($pagination->totalCount / $pagination->pageSize)),
'searchModel' => $searchModel
]);
}
I want to create $searchModel only after im pressing 'Filtering'.
again you need the model to render the form so you either create it or you only render the form if the model exists.
// in your index.php
if ($searchModel) {
/**
* your form here or $this->render('_form');
**/
}