PUGX / PUGXAutoCompleterBundle

Add an autocomplete field to your Symfony forms
GNU Lesser General Public License v3.0
93 stars 38 forks source link

Attempted to call an undefined method named #56

Closed devkbsc closed 4 years ago

devkbsc commented 5 years ago

I am using SF3.2. and pugx/autocompleter-bundle 1.3 the same error is still persisting,

Attempted to call an undefined method named "getId" of class "Doctrine\Common\Collections\ArrayCollection".

This is my source codes

Controller actions

public function searchSocieteAction(Request $request){
        $q = $request->query->get('q');
        $results = $this->getDoctrine()->getRepository('BlogBundle:Societe')->FindLikeName($q);

        return $this->render('dossier/test.html.twig', ['results'=> $results]);
    }

    public function getSocieteAction($id = null){

        $societe = $this->getDoctrine()->getRepository('BlogBundle:Societe')->find($id);

        return $this->json($societe->getNom());
    }

My Routes

dossier_societe_list:
    path:     /liste/societe
    defaults: { _controller: "BlogBundle:Dossier:searchSociete" }
    methods:  [GET, POST]

dossier_societe_get:
    path:     /get/societe
    defaults: { _controller: "BlogBundle:Dossier:getSociete" }
    methods:  [GET, POST]

My template

{% extends 'base.html.twig' %}

{% block body %}
    <div class="container-fluid">
        <div class="row">
            <h2 class="text-center top50" style="padding: 7px;background-color: #e2e2e2;">test autocomplete </h2>

            [{% for societe in results -%}
            {{ {id: societe.id, label: societe.name, value: societe.name}|json_encode|raw }}
            {# use "value" instead of "id" key, if you use jquery-ui #}
            {%- if not loop.last %},{% endif -%}
                {%- endfor %}]

            </div>
        </div>

        <script type="text/javascript">
            var URL_listSocietes = Routing.generate('api_autocomplete_societes', {}, true),
                    URL_getSociete = Routing.generate('api_autocomplete_societe', {}, true);
            $('#dossier').autocompleter({
                dossier_societe_list: URL_listClients,
                dossier_societe_get: URL_getClient
            });
        </script> 

{% endblock %}

what did i missed? i coudn't rectify as i am new to this bundle.

garak commented 5 years ago

I can't see any occurrence of getId in your code

devkbsc commented 5 years ago

Me neither, I didn't write anywhere! But the error existed!

garak commented 5 years ago

Maybe it's in societe.id, but it's hard to help you like so

devkbsc commented 5 years ago

societe.id, It was replaced from author object of your source code! i have just changed the object name to adapt my project! that's all!

garak commented 5 years ago

But I don't know what kind of object is societe. I can't debug your code

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

stale[bot] commented 4 years ago

This issue is closed because was marked as stale and had no activity. Thank you for your contributions.