php - cakePHP - How to solve a 'Trying to get property of non-object' error -


hello received error message when run application on server :

notice (8): trying property of non-object [app/template/applicanteducationneeds/view.ctp, line 52] 

and lines of code in 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 $applicantdesirededucation): ?>                             <tr> //here 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> 

but notice when ruining code in local machine works fine , promising solution precipitation

just guess, since not providing information error:

you looping through $applicantdesirededucations, not every $applicantdesirededucation has education_field_of_study_sub

so when call $applicantdesirededucation->education_field_of_study_sub->name_en error

you have insert check on exixtence of property, like

if(isset($applicantdesirededucation->education_field_of_study_sub)) {     echo h($applicantdesirededucation->education_field_of_study_sub->name_en);    } 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -