Call to a member function isAttributeRequired() on null

I’m suddenly getting the following error

Exception 'Error' with message 'Call to a member function isAttributeRequired() on null' 

in C:\home\site\vendor\yiisoft\yii2\widgets\ActiveField.php:932

Stack trace:
#0 C:\home\site\vendor\yiisoft\yii2\widgets\ActiveField.php(791): yii\widgets\ActiveField->addAriaAttributes()
#1 C:\home\site\backend\views\projects\_form_legs.php(598): yii\widgets\ActiveField->widget()
#2 C:\home\site\vendor\yiisoft\yii2\base\View.php(347): require('C:\\home\\site\\ba...')
#3 C:\home\site\vendor\yiisoft\yii2\base\View.php(257): yii\base\View->renderPhpFile()
#4 C:\home\site\vendor\yiisoft\yii2\base\View.php(156): yii\base\View->renderFile()
#5 C:\home\site\backend\views\projects\_form_update.php(1347): yii\base\View->render()
#6 C:\home\site\vendor\yiisoft\yii2\base\View.php(347): require('C:\\home\\site\\ba...')
#7 C:\home\site\vendor\yiisoft\yii2\base\View.php(257): yii\base\View->renderPhpFile()
#8 C:\home\site\vendor\yiisoft\yii2\base\View.php(156): yii\base\View->renderFile()
#9 C:\home\site\backend\views\projects\update.php(23): yii\base\View->render()
#10 C:\home\site\vendor\yiisoft\yii2\base\View.php(347): require('C:\\home\\site\\ba...')
#11 C:\home\site\vendor\yiisoft\yii2\base\View.php(257): yii\base\View->renderPhpFile()
#12 C:\home\site\vendor\yiisoft\yii2\web\View.php(220): yii\base\View->renderFile()
#13 C:\home\site\vendor\yiisoft\yii2\web\Controller.php(53): yii\web\View->renderAjax()
#14 C:\home\site\backend\controllers\ProjectsController.php(843): yii\web\Controller->renderAjax()
#15 [internal function]: backend\controllers\ProjectsController->actionUpdate()
#16 C:\home\site\vendor\yiisoft\yii2\base\InlineAction.php(57): call_user_func_array()
#17 C:\home\site\vendor\yiisoft\yii2\base\Controller.php(178): yii\base\InlineAction->runWithParams()
#18 C:\home\site\vendor\yiisoft\yii2\base\Module.php(552): yii\base\Controller->runAction()
#19 C:\home\site\vendor\yiisoft\yii2\web\Application.php(103): yii\base\Module->runAction()
#20 C:\home\site\vendor\yiisoft\yii2\base\Application.php(384): yii\web\Application->handleRequest()
#21 C:\home\site\wwwroot\admin\index.php(17): yii\base\Application->run()
#22 {main}

I don’t understand the error, or where to start looking exactly. Can anyone give any guidance.

Thank you,

No attribute name?

Not sure I understand.

I’ve posted everything I see in the developer tools. Same thing is repeated in the log file.

    protected function addAriaAttributes(&$options)
    {
        // Get proper attribute name when attribute name is tabular.
        $attributeName = Html::getAttributeName($this->attribute);

        if ($this->addAriaAttributes) {
            if (!isset($options['aria-required']) && $this->model->isAttributeRequired($attributeName)) {
                $options['aria-required'] = 'true';
            }
            if (!isset($options['aria-invalid']) && $this->model->hasErrors($attributeName)) {
                $options['aria-invalid'] = 'true';
            }
        }
    }

https://github.com/yiisoft/yii2/blob/master/framework/widgets/ActiveField.php#L926

https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php#L2262

I see those function in my Yii2 files.

Not sure what you want me to do exactly?

I think I got it wrong. Call on null, I guess that is meaning call on a null model.

if the issue is with my controller per:

#14 C:\home\site\backend\controllers\ProjectsController.php(843)
            return $this->renderAjax('update', [
                'model' => $model,
                'modelsNotes' => (empty($modelsNotes)) ? [new ProjectsNotes] : $modelsNotes,
                'modelsEmails' => (empty($modelsEmails)) ? [new Emails3] : $modelsEmails,
                'modelsLocks' => $modelsLocks,
                'modelsLegs' => (empty($modelsLegs)) ? [new ProjectsLegs] : $modelsLegs,
                'modelsLegsRates' => (empty($modelsLegsRates)) ? [new ProjectsLegsRates] : $modelsLegsRates,
                //'modelsLegsRates' => $modelsLegsRates,
            ]);

then it’s complaining about the $modelsLegsRates line.

The second to last call is to this function. Check if the reason is in the description. I don’t know more about this.

https://www.yiiframework.com/doc/api/2.0/yii-widgets-activefield#widget()-detail

I’ve isolated the issue and it is between the controller and my view.

'modelsLegsRates' => (empty($modelsLegsRates)) ? [new ProjectsLegsRates] : $modelsLegsRates,

foreach($modelsLegsRates[$i] as $ix => $modelLegRates):

obviously $modelLegRates is Null because if I test using !empty($modelLegRates) before the iteration I’m able to open the form in question.