Answer the question
In order to leave comments, you need to log in
How not to get an exception when returned NULL?
Knowledgeable people, tell me please.
How not to fall for symphony exceptions if the code is in the repository, for example
$this->em->getRepository(Test::class)->findOneBy(['test' => $test]);
Answer the question
In order to leave comments, you need to log in
Enter checks and that's it, hosh in php, hosh in twig and no errors will fly out
$test = $this->em->getRepository(Test::class)->findOneBy(['test' => $test]);
if (!empty($test)) {
$name = $test->getName();
$surname = $test->getSurname();
}
return $this->render('test/index.html.twig', [
'test' => $test,
'name' => $name ?? null,
'surname' => $surname ?? null
]);
// в твиге
{% if test is not null %}
<div>{{ test.name }}</div>
<div>{{ test.surname }}</div>
{% endif %}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question