带有存储库,查询构建器和KNP分页器的原始SQL CONCAT_WS

时间:2019-07-09 01:32:27

标签: symfony doctrine query-builder knppaginator concat-ws

如何查询以下内容:

SELECT CONCAT_WS('',apellido,nombre)AS名称FROM user 在哪里CONCAT_WS('',apellido,nombre)喜欢:busqueda

在symfony 4中,将其传递给KNP分页器?

    if($form->isSubmitted() && $form->isValid())
    {
        $data = $request->request->get('form');
        $buscar = $data['data'];

        $query = $userRepository->createQueryBuilder('p')
            ->andWhere('p.apellido LIKE :busqueda')
            ->setParameter('busqueda', '%'.$buscar.'%')
            ->orderBy('p.apellido', 'ASC')
            ->getQuery();

        $users = $paginator->paginate(
            $query,
            $request->query->getInt('page', 1),
            50
        );

        return $this->render('user/index.html.twig', [
            'users' => $users,
            'form' => $form->createView(),
        ]);
    }

0 个答案:

没有答案