symfony doctrine搜索查询与父实体

时间:2018-03-22 11:30:36

标签: symfony doctrine-orm

我正在使用knp paginator进行symfony 2.8项目 所以我一直在尝试创建costum过滤器问题是我用它来搜索父实体,我没有找到一种方法来做到这一点 这是我的控制器:

public function OfferIndex(Request $request)
{

    $em    = $this->getDoctrine()->getManager();
    $queryBuilder = $em->getRepository('BackBundle:offer')->createQueryBuilder('o');
    if (isset($_REQUEST['offerKey'])) {
        $queryBuilder
            ->where('CONCAT(o.name,o.technologies) LIKE :title')
            ->setParameter('title', '%' . $_REQUEST['offerKey'] . '%');
    }
    $query = $queryBuilder->getQuery();

    $paginator  = $this->get('knp_paginator');
    $pagination = $paginator->paginate(
        $query, /* query NOT result */
        $request->query->getInt('page', 1)/*page number*/,
        2/*limit per page*/
    );

    return $this->render('FrontBundle:pages:Offre d\'emploi et de stage .html.twig',array(
        'pagination' => $pagination
    ));
}

这个过滤器是我的树枝:

<form method="post" id="filtres" action="{{ path('offer/list') }}">
    <div class="filter with-reset-search">
        <input type="text" placeholder="Mots clés" id="offerKey" name="offerKey"/>
            <span class="reset-search">
                <svg version="1.1" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"
                                 xmlns:xlink="http://www.w3.org/1999/xlink"><g id="icons" fill="#0064b9"><path
                                            d="M14.8,12l3.6-3.6c0.8-0.8,0.8-2,0-2.8c-0.8-0.8-2-0.8-2.8,0L12,9.2L8.4,5.6c-0.8-0.8-2-0.8-2.8,0   c-0.8,0.8-0.8,2,0,2.8L9.2,12l-3.6,3.6c-0.8,0.8-0.8,2,0,2.8C6,18.8,6.5,19,7,19s1-0.2,1.4-0.6l3.6-3.6l3.6,3.6   C16,18.8,16.5,19,17,19s1-0.2,1.4-0.6c0.8-0.8,0.8-2,0-2.8L14.8,12z"
                                            id="exit"></path></g></svg>
    </span>
</div>

我想要的是在搜索查询中添加父实体:

$queryBuilder
            ->where('CONCAT(o.name,o.technologies) LIKE :title')
            ->setParameter('title', '%' . $_REQUEST['offerKey'] . '%');

我努力在学说文档https://symfony.com/doc/2.8/doctrine.html中找到这个 但没有任何帮助。

1 个答案:

答案 0 :(得分:0)

我找到了带有学说的解决方案,它不是最好的解决方案,但它目前有效:

vertical-align