Yii2 - Trying to get property of non-object

How do I resolve this error

7651

non property.PNG

I think this problem came because it cannot find the item. But I don’t know how to resolve it.

Controller




    public function actionCourseTopics($csid)

    {

        $coursetopics = CourseStructure::find()->where(['structure_course_id' => $csid])->One();

        $csidx = $coursetopics->structure_course_id; 


        $searchModel = new CourseStructureSearch();

        $dataProvider = $searchModel->searchtopics(Yii::$app->request->queryParams, $csidx);

        $dataProvider->pagination->pageSize=10;


        return $this->render('course-topics', [

            'searchModel' => $searchModel,

            'dataProvider' => $dataProvider,

        ]);      

    }



ModelSearch




    public function searchtopics($params,$csidx=null)

    {

        $query = CourseStructure::find()->where(['=', 'structure_course_id', $csidx]);


        // add conditions that should always apply here


        $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;

        }


        // grid filtering conditions

        $query->andFilterWhere([

            'course_structure_id' => $this->course_structure_id,

            'structure_course_id' => $this->structure_course_id,

            'structure_id' => $this->structure_id,

            'summary_format' => $this->summary_format,

            'created_at' => $this->created_at,

            'created_by' => $this->created_by,

            'updated_at' => $this->updated_at,

            'updated_by' => $this->updated_by,

        ]);


        $query->andFilterWhere(['like', 'structure_name', $this->structure_name])

            ->andFilterWhere(['like', 'structure_summary', $this->structure_summary]);


        return $dataProvider;

    }



Thanks

$coursetopics not object.