您好,我在服务器上运行应用程序时收到此错误消息:
Notice (8): Trying to get property of non-object [APP/Template/ApplicantEducationNeeds/view.ctp, line 52]
,这是view.ctp中的代码行:
<?php
use Cake\Cache\Cache;
use Cake\Core\Configure;
use Cake\Datasource\ConnectionManager;
use Cake\Error\Debugger;
use Cake\Network\Exception\NotFoundException;
$this->layout = 'userProfile';
if (!Configure::read('debug')):
throw new NotFoundException();
endif;
//echo debug($applicantDesiredEducations);
?>
<div class='col-md-12'>
<div class="applicantGenerals view large-9 medium-8 columns content">
<div class ='col-md-4'>
<h3><?= __('Desired Education') ?></h3>
<table class="table">
<thead>
<tr>
<th><?= __('Field Of Studies') ?></th>
<th class="actions"><?= __('Actions') ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($applicantDesiredEducations as $applicantDesiredEducation): ?>
<tr>
//here the lines of 50's
<td><?= $_language == 'en_US' ? h($applicantDesiredEducation->education_field_of_study_sub->name_en) : h($applicantDesiredEducation->education_field_of_study_sub->name_ara) ?></td>
但请注意,当我在本地机器中破坏此代码时,它的工作正常,任何有希望的解决方案都会降水
答案 0 :(得分:1)
只是一个猜测,因为您没有提供有关您的错误的更多信息:
您正在循环浏览$applicantDesiredEducations
,但可能不是每个$applicantDesiredEducation
都有education_field_of_study_sub
因此,当您致电$applicantDesiredEducation->education_field_of_study_sub->name_en
时,您会收到该错误
你必须检查房产的外观,例如
if(isset($applicantDesiredEducation->education_field_of_study_sub))
{
echo h($applicantDesiredEducation->education_field_of_study_sub->name_en);
}