Karthik Gridview Expand Row : Trying to get property of non-object

i just followed this video From DoingITeasyChannel : Karthik Gridview Expand Row

when i try it … it gives me :


Trying to get property of non-object

my index.php code :


 <?= GridView::widget([

        'dataProvider' => $dataProvider,

        //'dataProvider'=>$model->search(), 


        'filterModel' => $searchModel,

               

        'columns' => [

           [

            'class'=>'kartik\grid\ExpandRowColumn', 

            'value'=> function($model, $key, $index, $column){

                return GridView::ROW_COLLAPSED;

            },

            'detail' => function ($model, $key, $index, $column){

                $searchModel =new receivedbodySearch();

                $searchModel->recev_id=$model->id;   // [b]here is the problem [/b]

                 $dataProvider=$searchModel->search(yii::$app->request->queryParams);

                 return Yii::$app->controller->renderPartial('_poitemes',[

                    'searchModel'=>$searchModel,

                    'dataProvider'=>$dataProvider,

                    ]);

                    }

                ],

                'itemes_id',  

                'quantity',

                ['class'=>'yii\grid\ActionColumn'],

                ],

                ]);?>



My receivedbodySearch.php code :




 public function search($params)

    {

        $query = receivedbody::find();


        $dataProvider = new ActiveDataProvider([

            'query' => $query,

        ]);


        $this->load($params);


        if (!$this->validate()) {

            // uncomment the following line if you do not want to return any records when validation fails

            // $query->where('0=1');

            return $dataProvider;

        }

        $query->joinWith('receivedhead');

        $query->andFilterWhere([

            'id' => $this->id,

            'recev_id' => $this->recev_id,

            'item_no' => $this->item_no,

            'quantity' => $this->quantity,

            'sale_price' => $this->sale_price,

            'cost_price' => $this->cost_price,

            'total' => $this->total,

        ]);


        return $dataProvider;

    }

}

idunno what i should do … and i’m new in YII !

Stacktrace had to show what line the error. Can you throw out more about the error from stack trace?

Hi Naeem Marzu,

Ok $model is null.

Can you check your dataProvider if is null?

No its not null there is data in the table .