Les EntityRepository permettent d'associer des méthodes aux requêtes
namespace AppBundle\Repository;
use Doctrine\ORM\EntityRepository;
class LivreRepository extends EntityRepository
{
public function findAllOrderedByLivTitre()
{
return $this->getEntityManager()
->createQuery(
'SELECT l FROM AppBundle:Livre l ORDER BY l.livTitre ASC'
)
->getResult();
}
public function findAllOrderedBy(string $colname, $sort = 'ASC') {
return $this->getEntityManager()
->createQuery(
'SELECT l FROM AppBundle:Livre l ORDER BY l.'.$colname.' '.$sort
)
->getResult();
}
}