I can't find any supporting resources for the error Call to a member function formName() on null. The scenario of getting this error when opening a update page. I've checked the rendered variable on update page by print_r() and its fine. Then I checked by removing the all input field which codes in yii2 ActiveFrom chtml
<?= $form->field($model, 'name')->textInput(['maxlength' => true, 'class' => ' form-control']) ?>
and kept some input fields which is in normal html syntax
<input type="text" class="qty" name="qty[]" value="1" style="width: 24px;" value="<?php echo $value->qty; ?>">
Then it worked. Why this error occurred and how to fix it. Thanks,
You are probably not passing an update model from controller's action to view. Make sure you pass the loaded model in your update action to view like this:
If you are using some common
_formtemplate that you include into your create/update templates you also have to make sure the$modelis passed from yourupdatetemplate to the_formtemplate.Another option is that you are overwiriting the $model variable somewhere in your templates.