S
S
Skrolea2016-04-03 16:51:03
Yii
Skrolea, 2016-04-03 16:51:03

Why does Call to a member function formName() on a non-object issue in Yii2?

I am making a form (related model) to save an article in Russian and English

<div class="about-form">

    <?php $form = ActiveForm::begin(); ?>

    <?= $form->field($model, 'status')->textInput() ?>
    
    <?= $form->field($langru, 'title')->textInput() ?>
    
    <?= $form->field($langru, 'content')->textInput() ?>



    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>

Controller
public function actionCreate()
    {
        $model = new About();
        $langru = new AboutLang();
        $langen = new AboutLang();

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
              return $this->redirect(['view', 'id' => $model->id]);
        } else {
            return $this->render('create', [
                'model' => $model,
                'langru' =>$langru,
                'langen' =>$langen
            ]);
        }
    }

I get an error
Call to a member function formName() on a non-object
Why?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2016-04-03
@webinar

Your $model is clearly null in your form. So either a typo, or troubles in the model.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question