applicantDesiredEducation

applicantDesiredEducation

本文介绍了cakePHP-如何解决“尝试获取非对象的属性"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我在服务器上运行应用程序时收到此错误消息:

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>

但是请注意,当我在本地计算机上破坏此代码时,它的工作正常,任何有前途的解决方案都是沉淀

but notice when i ruining this code in my local machine its works fine , any promising solution it will be precipitation

推荐答案

只是一个猜测,因为您没有提供有关错误的太多信息:

just a guess, since you are not providing much information about your error:

您正在遍历 $ applicantDesiredEducations ,但是可能不是每个 $ applicantDesiredEducation 都有一个 education_field_of_study_sub

you are looping through $applicantDesiredEducations, but probably not every $applicantDesiredEducation has an education_field_of_study_sub

因此,当您致电 $ applicantDesiredEducation-> education_field_of_study_sub-> name_en 时,会收到该错误

So when you call $applicantDesiredEducation->education_field_of_study_sub->name_en you get that error

您必须在属性的存在处插入一个检查,例如

you have to insert a check on the exixtence of the property, something like

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

这篇关于cakePHP-如何解决“尝试获取非对象的属性"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 13:43