How can I choose(filter) on my controller which fields I want (or don't want) to pass to my frontend?
my Controller:
/**
* @Route("/", name="dashboard")
*/
public function index()
{
$aniversariantes = $this->getDoctrine()->getRepository(Usuario::class)->aniversariantes();
return $this->render('dashboard/index.html.twig', [
'controller_name' => 'DashboardController',
'aniversariantes' => $aniversariantes
]);
}
My repository:
/**
* @return []
*/
public function aniversariantes(): array
{
$qb = $this->createQueryBuilder('u')
->andWhere('u.ativo = 1')
->andwhere('extract(month from u.dtNascimento) = :hoje')
->setParameter('hoje', date('m'))
->getQuery();
return $qb->execute();
}
Dump from entity:
What can I do if I don't want to pass the "password" field for example?
If you are just trying to prevent certain fields from being dumped, it is useful to know
https://twig.symfony.com/doc/2.x/functions/dump.html
This means you can can define the PHP magic method
__debugInfo
in your entityhttps://www.php.net/manual/en/language.oop5.magic.php#object.debuginfo
So in your entity do something like this: