Trying to get property of non-object

Am trying to array mapping and I have this error. "Trying to get property of non-object"

7177

Object Error.PNG

Controller




    public function actionZonalmapping()

    {


        $user = Yii::$app->getid->getId();

         $zonalSession = Yii::$app->session->get('zonal_id');

         $ZonalMaster = ZonalAdministrator::find()->andWhere(['zonal_id' => $zonalSession])->one();

         $ZonalInfo = ZonalAdministrator::findOne($ZonalMaster->zonal_id);

         $zonalZone = Zone::findOne($ZonalMaster->zone_id);

         $zone = $ZonalInfo->zone_id;


            $inspector = new Inspector();

            $inspector=Inspector::find()->andWhere(['zone_id' => $zone])->one();


            $inspectionmapping = new InspectionMapping();

            $inspectionmapping=InspectionMapping::find()->andWhere(['zone_id' => $zone, 'is_mapped_to_zone' => 1])->one();


        if(isset($_POST['submit'])){

            if($_POST['submit']=='Save'){


                if(isset($_POST['Inspector'])){

                    $inspectionmapping = new InspectionMapping();


                    foreach ($_POST['Inspector']['inspection_mapping'] as $key=>$value)

                    {

                       // $inspectionmapping=$inspectionmapping->findByPk($key);

                        //$inspectionmapping=InspectionMapping::findOne($key);

                        $inspectionmapping=InspectionMapping::find($key)->One();

                    //    $model = User::findOne(['username'=>'filip','password'=>'admin']);

                        $inspectionmapping->company_id=$value['company_id'];

                        $inspectionmapping->is_mapped_to_inspector= 1;

                        $inspectionmapping->save();

                    }

                }

   

            }

                    return $this->redirect('index');            

          

        }            


        return $this->render('zonalmapping', [

            'inspector' => $inspector,

            'inspectionmapping' => $inspectionmapping,

                ]); 

    }



view




<div class="col-xs-12 col-lg-12">


<!--<div class="inspector-update">  -->


<!--</div>-->

<!--</div>-->

<div class="mapping-form">

  <?php $form = ActiveForm::begin(['id' => 'inspection-form']); ?>


<h1>Building(s) Mapping to Inspector(s)</h1>


<!-- Main content -->

<section class="content">

      <div class="row">

        <div class="col-xs-12">


          <div class="box">

            <div class="box-header">

              <h3 class="box-title">Mapping: Building(s) to Inspector(s)</h3>

            </div>

      <!-- /.box-header -->

            <div class="box-body">

              <table id="example1" class="table table-bordered table-striped">

                <thead>

                <tr>     

                  <th>#</th>

                  <th>Building</th>

                  <th>Zone</th>

                  <th>Fee</th>

                  <th>Tariff Group</th>

                  <th>Inspector</th>

                </tr>

                </thead>

                <tbody>


    <?php 

      $i = 1;

      $key = 0;

    foreach ($inspectionmapping as $cvalue) 

    {

     ?>                  

                <tr>

                  <td><?php echo $i++;?></td>


                  <td><?php echo $cvalue->building->building_name; ?></td>

                  <td><?php echo $cvalue->zone->zone_name; ?></td>

                  <td><?php echo $cvalue->fee->value; ?></td>

                  <td><?php echo $cvalue->tariff->tariff_group_detail; ?></td>

                  <td>


                  <?php 

                  $name="Inspection[inspection_mapping][$cvalue[company_id]][inspector_name]";

                      $yn=array("$cvalue[inspector]"=>array('selected'=>true));

                  echo $form->field($inspector, 'company_id')->dropDownList(ArrayHelper::map(\app\modules\contractors\models\Inspector::find()->all(),'company_id','inspector_name'), ['name'=>$name,'options'=>$yn])->label(false);

                      ?> 


                  </td>

                </tr>

    <?php 

    }

    ?>


            </tbody>               

              </table>

            </div>


      </div>




        </div>

        <!-- /.col -->

      </div>

      <!-- /.row -->

</section>

<!-- /.content -->


<?php ActiveForm::end(); ?>

</div>  <!-- /.End of Inspection Sheet -->

</div>  <!-- /.End of col-xs-12 col-lg-12 -->



Please help me

cvalue has no building but you’re trying to get property of the building. Thus the error.

Thanks a lot