变量可在服务中使用

时间:2017-09-25 08:11:52

标签: php symfony variables

我是php的初学者。我有一个WadoService服务和一个StudiesRestController控制器。我想在服务中使用控制器数据。

public function getPatientAction(Request $request, $studyUID)
{
    $studyRepository = new StudyRepository(
        $this->get('nexus_db'),
        $this->get('logger'),
        $this->get('translator')
    );

    $study = $studyRepository->getStudy($studyUID);
    if (!$study) {
        throw new NotFoundHttpException("No study found with studyuid $studyUID");
    }

    $patientInfo = new RestResponse(
        SerializerBuilder::create()
            ->build()
            ->serialize($study->getPatient(), 'json')
    );

    return $patientInfo;
}

这可能吗?我试图把它放在函数getPatientAction()中,但没有结果:

/* @var $wadoService WadoService */
    $wadoService = $this->container->get(WadoService::SERVICE_NAME);

   $wadoService = new RestResponse(
        SerializerBuilder::create()
            ->build()
            ->serialize($study->getPatient(), 'json')
    );

1 个答案:

答案 0 :(得分:2)

要将控制器中的变量传递给您的服务,您可以这样做:

$wadoService = $this->container->get(WadoService::SERVICE_NAME)->yourServiceMethod($yourVari);