Answer the question
In order to leave comments, you need to log in
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>
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
]);
}
}
Call to a member function formName() on a non-object
Why?
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question