79361003

Date: 2025-01-16 09:38:32
Score: 1
Natty:
Report link

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');
 **/
}
Reasons:
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Sakurai Evsa