S
S
Sergey Beloventsev2016-07-15 11:35:19
Yii
Sergey Beloventsev, 2016-07-15 11:35:19

Why does the Call to a member function load() on null error occur?

Actually here is the code

$model= new Watch();
        if($this->classes == 'serial'){
                $feild='id_serial';
                $model= $model->id_serial;}
        if($this->classes == 'film'){
                 $feild='id_film';
                $model= $model->id_film;}
        if($this->classes == 'mfilm'){
                $feild='id_mfilm';
                $model= $model->id_mfilm;}
        $wathCount= Watch::find()->where(['id_serial'=>$this->serial->id,'active'=>1])->count();
        $guest=false;
        if ($model->load(Yii::$app->request->post()))
        { ...

swears at this line if ($model->load(Yii::$app->request->post()))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2016-07-15
@Sergalas

because you are overwriting the $model variable in three places

if($this->classes == 'serial'){
                $feild='id_serial';
                $model= $model->id_serial;} // тут
        if($this->classes == 'film'){
                 $feild='id_film';
                $model= $model->id_film;} // тут
        if($this->classes == 'mfilm'){
                $feild='id_mfilm';
                $model= $model->id_mfilm;} // тут

and at the time of calling $model->load() in the $model variable is no longer an object of the ActiveRecord class, but another value that does not have the load() method

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question