Floriane
Floriane

Reputation: 315

Variable usable in Service

I am a beginner in php. I have a WadoService service and a StudiesRestController controller. I want to use controller data in the service.

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;
}

Is this possible? I have tried to put this in the function getPatientAction()without result:

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

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

Upvotes: 0

Views: 50

Answers (1)

t-n-y
t-n-y

Reputation: 1209

To pass a variable from your controller to your service, you do it it like that :

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

Upvotes: 2

Related Questions