Filtering yii2 produces an error Call to a member function isAttributeRequired () on null

Viewed 916

I'm trying to filter on yii2. There is a form field in it 3 input (type = "radio"), each entry should search for products with a price in this range. Here is the controller code where the search is performed :

 public function actionFilter()
        {
            $filter = trim(Yii::$app->request->get('filter'));
            $this->setMeta('MAC-SHOPPER | ' . $filter);
            if (!$filter) {
                return $this->render('filter');
            }
/*
            if ($filter <= 15) {

            $query = Product::find()->where(['<=', 'price', 15]);
            }*/

            $model = new Product();
            if($Button1) {
                $query = Product::find()->where(['between', 'price', "0", "50" ])->all();
            }

            $pages = new Pagination(['totalCount' => $query->count(), 'pageSize' => 2, 'forcePageParam' => false, 'pageSizeParam' => false]);

            $products = $query->offset($pages->offset)->limit($pages->limit)->all();
            return $this->render('filter', compact('products', 'pages', 'filter', 'model'));
        }

Product Model Code:

<?php
    namespace app\models;
    use yii\db\ActiveRecord;
    class Product extends ActiveRecord
    {
        public $Button1;
        public $Button2;
        public $Button3;
        public $radioButtonList;


             public function behaviors()
        {
            return [
                'image' => [
                    'class' => 'rico\yii2images\behaviors\ImageBehave',
                ]
            ];
        }




        public static function tableName()
        {
            return 'product';
        }

        public function getCategory()
        {

            return $this->hasOne(Category::className(), ['id' => 'category_id']);
        }



    }
?>

And the code of the form itself:

<?php $form = ActiveForm::begin([
                                'id' => 'task-form',
                                'action' => \yii\helpers\Url::to(['category/filter']),
                                ]  
                                )?>





                         <?= $form->field($model, 'radioButtonList')
                                ->radioList([
                                    'Button1' => 'от 0-1500',     
                                    'Button2' => 'от 3000-5000',
                                    'Button3' => 'от 5000-20000'
                                ],[
                                    'id' => 'radio_button',

                                ]); ?>
                            <?= Html::submitButton('Найти', ['class' => 'btn btn-success']);?>
                        <?php $form = ActiveForm::end() ?>

How do I put in the properties $ Button1, $ Button2, $ Button3 price from the table of goods, so that when I click on a certain inference, he displays the goods as done in the controller's condition (that is, by the price range)

1 Answers
Related