-2

I am getting data via doctrine:

$pages = $this->getDoctrine()->getRepository(Pages::class)->findAll();

What I want to to is get all data, except the data with the slug cat

So I trying to achieve something like this:

$pages = $this->getDoctrine()->getRepository(Pages::class)->findAllExcept(['slug'=>'cat']);
peace_love
  • 6,229
  • 11
  • 69
  • 157

1 Answers1

4

It is good practice to use custom repository class.

<?php

namespace AppBundle\Repository;

use AppBundle\Entity\Pages
use Doctrine\ORM\EntityRepository;

class PagesRepository extends EntityRepository
{
    /**
     * @param $slug
     * @return Pages[]
     */
    public function findAllExceptThis($slug)
    {
        return $this->createQueryBuilder('pages')
            ->andWhere('pages.slug != :slug')
            ->setParameter('slug', $slug)
            ->getQuery()
            ->execute();
    }
}
Zamir
  • 449
  • 1
  • 8
  • 17