Home > Software engineering >  Access a property from another property in controller
Access a property from another property in controller

Time:08-26

I'm bulding a webapp in Symfony, and I need to access to some properties of an entity in a controller to add this values to $candidature entity. Thank you for the help.

Controller.php :

class CandidatureController extends AbstractController
{
#[Route('/candidature', name: 'app_candidature')]
public function index(EntityManagerInterface $entityManager): Response
{
    $candidature = new Candidature();

    //$candidatNom = $entityManager->getRepository(ProfileCandidat::class)->findBy($Nom);

    $candidature->setNom($candidatNom);
    $candidature->setPrenom('Charles');
    $candidature->setCv('cv');
    $candidature->setPostId('4');

    $entityManager->persist($candidature);
    $entityManager->flush();
    return $this->render('candidature/index.html.twig', [
        'controller_name' => 'CandidatureController',
    ]);
}
}

CodePudding user response:

$candidatNom = $entityManager->getRepository(ProfileCandidat::class)->findBy(['nom' => $Nom);

should do the trick

  • Related