2

私は symfony プロジェクト (Doctrine も使用) に取り組んでおり、例に従って、ページの 1 つに時差検索を実装したいと考えています。

ユーザーは最初の select2 ボックス (Ajax を介して DB からデータをプルする) で著者を検索し、アイテムが選択されると、選択した著者に属するタイトルのみを表示したい、タイトルと呼ばれる 2 番目の select2 ボックスがあります。 .

以下は、最初のボックスのコントローラー側のコード (Ajax とコントローラーの両方) です。2 番目の select2 のクエリを作成する方法はありますか?

結果と自動提案された項目について DB にクエリを実行する最初の select2 に関連する部分:

public function searchAjaxAuthorAction()
{
    $em = $this->getDoctrine()->getManager();

    $term = $this->get('request')->query->get('term');
    $limit = $this->get('request')->query->get('page_limit', 1);

    $rep = $em->getRepository('StephenPersianArtBundle:Main');

    if($term){
        $entities = $rep->createQueryBuilder('m')
            ->where('m.orig_author LIKE ?1')
            ->orderBy('m.orig_author', 'ASC')
            ->setParameter('1','%'.$term.'%')
            ->getQuery();
    }else{
        $entities = $rep->createQueryBuilder('m')
            ->groupBy('m.orig_author')
            ->getQuery();
    }

    $entities = $entities->execute();

    $resultset = array();

    foreach($entities as $entity){
        if($entity->getOrigAuthor()){
            $resultset[] = array(
                //'id' => $entity->getId(),
                'id' => $entity->getOrigAuthor(),
                'text' => $entity->getOrigAuthor()
            );
        }
    }

    $return = json_encode($resultset);//jscon encode the array
    return new Response($return,200,array('Content-Type'=>'application/json'));
}

これに関連して、基本的に select2 で選択されたアイテムに基づいてデータをテーブルにロードする別の部分もありますが、これはすべて最終クエリが完了する前に発生しているため、私が抱えている問題には関係ないと考えています。

どんな助けでも大歓迎です!

4

0 に答える 0