Symfony 错误 - 无法访问私有 属性 AppBundle\Entity\VacancyEntity::$job 描述

Symfony Error -Cannot access private property AppBundle\Entity\VacancyEntity::$jobDescription

当我尝试访问 symfony 2.8 中的提取结果时出现此错误。这是我的代码

 public function staticAction(Request $request)
    {   


      $jobid = $this->get('session')->get('jobid');
      $jobDetails = $this->getVacancyData($jobid);
      echo "<pre>";
      var_dump($jobDetails);
      $description = $jobDetails->jobDescription;


      return $this->render('FrontEnd/job.html.twig', array('jobdetails' => $jobDetails ));
    }

    public function getVacancyData($id){

        $vacancy = $this->getDoctrine()
        ->getRepository(VacancyEntity::class)
        ->findOneBy(array('id' => $id));


        if (!$vacancy) {
            throw $this->createNotFoundException();
        }else{
            return $vacancy;
        }  

    }

下一行发生错误,

$description = $jobDetails->jobDescription;

如何解决?

我认为您需要这样调用 getter:

$description = $jobDetails->getJobDescription();

因为在你的实体中属性是私有的,所以你需要使用 getter

我不知道在你的实体中是否有一个名为 getJobDescription 的 getter 但它应该有一个 return 属性 jobDescription