Problem Fetching related model attribute in detail form


I am trying to access the related model attributes value/label using the following code

<?= Html::activeLabel($model->profile->offices, 'number',['class'=> 'profile-page-label']); ?>

the problem is when profile table have empty office id it gives me the following error

Call to a member function formName() on a non-object

how can i by bass this error when the office id in profile table is null or not found!

Thank You

You need to check if [size=2]$model[/size][color=#666600][size=2]->[/size][/color][size=2]profile is set… use something like[/size]




isset($model->profile) ? $model->profile->offices : 'n/a'


when i check $model->profile it always returns true because model has related profile but when i go beyond profile by


it gives me the error.because office does not exist for the profile model.Now The Error is

Trying to get property of non-object