2016-09-25 16:30
浏览 39


My FAQ System is working well, but I want to include a search function with Select2.

What I got so far:

Select2 AJAX Script

        ajax: {
            url: "/ajax/searchallSelect2",
            dataType: 'json',
            delay: 250,
            data: function (params) {
                return {
                    q: params.term, // search term
            processResults: function (data, params) {
                // parse the results into the format expected by Select2
                // since we are using custom formatting functions we do not need to
                // alter the remote JSON data, except to indicate that infinite
                // scrolling can be used
       = || 1;

                return {
                    results: data.items,
                    pagination: {
                        more: ( * 30) < data.total_count
            cache: true
        escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
        minimumInputLength: 1,


 * @Route("/ajax/searchallSelect2", name="ajax_searchall_select2")
public function searchallSelect2Action(Request $request)
    return $this->render('', array('name' => $name));

Select2 Form in "index.html.twig"

    <select id='searchall' style="width: 300px">

Firebug console output after typing in the select2 search field:

GET http://localhost:8000/ajax/searchallSelect2?q=test 200 OK 16ms

My question is, how do I implement the database searching? Simply with getRepository in the AjaxController?

        $allfaqs = $this->getDoctrine()

Or do I need to search the database in the Ajax script?

Any help is greatly appreciated, thank you for reading!

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题