# Autocomplete not working.. 404

**URL:** <https://discourse.cakephp.org/t/autocomplete-not-working-404/9716>\
**Category:** Need Help\
**Created:** [September 15, 2021, 4:29pm UTC](https://discourse.cakephp.org/t/autocomplete-not-working-404/9716 "2021-09-15T16:29:10Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Herzberg](https://avatars.discourse-cdn.com/v4/letter/h/74df32/32.png) [@Herzberg](https://discourse.cakephp.org/u/Herzberg)\
**Post date:** [September 15, 2021, 4:29pm UTC](https://discourse.cakephp.org/t/autocomplete-not-working-404/9716/1 "2021-09-15T16:29:10Z")

</div>

Hey,

i found a Autocomplete Snippet here in this Forum and I tried to use it for my purpose but its not working. I tried to autocomplete the email address but it says:

toolbar.js?1627302522:91 GET [http://localhost/users/get-ajaxlist?term=test](http://localhost/users/get-ajaxlist?term=test) 404 (Not Found)

**UsersController:**  
public function getAjaxList()  
{  
$this-\>autoRender = false;

```
if ($this->request->is('ajax')) {
    
    $name = $this->request->getQuery('term');
    $results = $this->Users->find('all', [
        'conditions' => ['email LIKE' => $name . '%'],
        'limit' => 10,
        'fields'=>['id','email']
    ]);
    // debug($results);
    $resultsArr = [];
    
    foreach ($results as $result) {
        $resultsArr[] =['label' => $result['email'], 'value' => $result['id']];
    }
    
    return $this->response->withType('application/json')->withStringBody(json_encode($resultsArr));
}

```

}

**index.php**

 \<?= $this-\>Form-\>create(null,['type'=\>'get']) ?\>

```
 <?= $this->Form->control('email', ['type' => 'text', 'autocomplete' => 'off']); ?>
<?= $this->Form->submit() ?>
<?= $this->Form->end() ?>

```

**javascript:**

$(document).ready(function(){

```
jQuery('#email').autocomplete({
    source:'<?= $this->Url->build(["controller" => "Users", "action" => "getAjaxlist"],["fullBase" => true,]); ?>',
    minLength: 2,
    delay:0,
    select: function(event, ui) {
            event.preventDefault();
            $("email").val(ui.item.label);
    },

    focus: function(event, ui) {
            event.preventDefault();
            $("#email").val(ui.item.label);
    }
});

```

});

**Database:**

CREATE TABLE `users` (  
`id` int(10) UNSIGNED NOT NULL,  
`email` varchar(255) DEFAULT NULL,  
`password` varchar(255) DEFAULT NULL,  
`created` datetime DEFAULT NULL,  
`modified` datetime DEFAULT NULL  
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [September 15, 2021, 8:07pm UTC](https://discourse.cakephp.org/t/autocomplete-not-working-404/9716/2 "2021-09-15T20:07:04Z")

</div>

If your function name is `getAjaxList`, I think the URL would be `get-ajax-list`, not `get-ajaxlist`. Your “action” in your JavaScript is “getAjaxlist”, which doesn’t match your actual controller function name.

---

<div class="post-metadata">

**Author:** ![Herzberg](https://avatars.discourse-cdn.com/v4/letter/h/74df32/32.png) [@Herzberg](https://discourse.cakephp.org/u/Herzberg)\
**Post date:** [September 15, 2021, 8:41pm UTC](https://discourse.cakephp.org/t/autocomplete-not-working-404/9716/3 "2021-09-15T20:41:06Z")

</div>

the autocomplete is working so far… but i dont understand why I have to change it like that… the function is called getAjaxList(). So even the get-ajaxlist was wrong to me!  
Now i need to write:  
source:’\<?= $this-\>Url-\>build(["controller" =\> "Users", "action" =\> "getAjax-list"],["fullBase" =\> true,]); ?\>’,

crazy but thank you!

But now I can only use Autocomplete if i say:

$this-\>Authorization-\>skipAuthorization();

otherwise with ​:  
$this-\>Authorization-\>authorize($user);

he says:  
{message": “Policy for `NULL` has not been defined.”, “url”: “/users/get-ajax-list?term=hallo”, “code”: 500, “file”: “/var/www/html/r/vendor/cakephp/authorization/src/Policy/OrmResolver.php”, “line”: 85

---

<div class="post-metadata">

**Author:** ![Herzberg](https://avatars.discourse-cdn.com/v4/letter/h/74df32/32.png) [@Herzberg](https://discourse.cakephp.org/u/Herzberg)\
**Post date:** [September 15, 2021, 8:49pm UTC](https://discourse.cakephp.org/t/autocomplete-not-working-404/9716/4 "2021-09-15T20:49:05Z")

</div>

ah i see you have to add the policy to the PolicyController:

```
public function canGetAjaxList(IdentityInterface $user, User $resource)
{
return true;
}

```

and also edit the function in the UserController:

$user = $this-\>Users-\>get($this-\>request-\>getAttribute(‘identity’)-\>getIdentifier(), [  
‘contain’ =\> [‘Details’],  
]);

---

<div class="post-metadata">

**Author:** ![Herzberg](https://avatars.discourse-cdn.com/v4/letter/h/74df32/32.png) [@Herzberg](https://discourse.cakephp.org/u/Herzberg)\
**Post date:** [September 15, 2021, 8:51pm UTC](https://discourse.cakephp.org/t/autocomplete-not-working-404/9716/5 "2021-09-15T20:51:36Z")

</div>

how can I use multiple input fields that depend on each other?

E.g if i want to request the Country, City and the Area but the Autocomplete depends on the Country to get the correct suggestions for the City and so on…

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [September 15, 2021, 9:19pm UTC](https://discourse.cakephp.org/t/autocomplete-not-working-404/9716/6 "2021-09-15T21:19:40Z")

</div>

The function is called `getAjaxList`, so use `'action' => 'getAjaxList'` when you build the URL. You had `'action' => 'getAjaxlist'`, see the difference?

It’s saying there’s no policy for NULL, because you haven’t defined `$user`. And that’s probably not what you want to pass anyway. The argument given to `authorize` is the resource that you are authorizing access _to_, e.g. permission to edit a particular record might check whether you own that record, or are part of a group that is allowed to edit it based on some status or relation. The details of the user are available internally already, you don’t need to pass them here. I can’t say what would make sense for you here, but `$user` is almost certainly wrong.

To make fields depend on each other, you’ll need to have more JavaScript that pulls values from the form and passes them as part of the URL. There should be lots of tutorials out there about how to do that, it’s nothing Cake-specific.

---

<div class="post-metadata">

**Author:** ![Herzberg](https://avatars.discourse-cdn.com/v4/letter/h/74df32/32.png) [@Herzberg](https://discourse.cakephp.org/u/Herzberg)\
**Post date:** [September 15, 2021, 9:38pm UTC](https://discourse.cakephp.org/t/autocomplete-not-working-404/9716/7 "2021-09-15T21:38:32Z")

</div>

but the policy function is called ’ canGetAjaxList’ so the authorize argument checks if this user is allowed to get ajax lists…

ok i will check that later because im not that familiar with policies yet! the given policy for articles from the tutorial was simple but for users it seems to be different…

well, i tried to request the profile.name with almost the same code that i used before but this is not working:

Index.php

 \<?= $this-\>Form-\>control('\*\*profile.name\*\*', ['type' =\> 'text', 'autocomplete' =\> 'off']); ?\>

Javascript:  
$(document).ready(function(){

```
jQuery('#profile-name').autocomplete({
    source:'<?= $this->Url->build(["controller" => "Users", "action" => "getAjax-list"],["fullBase" => true,]); ?>',
    minLength: 2,
    delay:0,
    select: function(event, ui) {
            event.preventDefault();
            $("profile.name").val(ui.item.label);
    },

    focus: function(event, ui) {
            event.preventDefault();
            $("#profile.name").val(ui.item.label);
    }
});

```

});

UserController:

public function getAjaxList()  
{  
$this-\>autoRender = false;

```
if ($this->request->is('ajax')) {
    
     ]);
    
    $this->Authorization->skipAuthorization();      
    $name = $this->request->getQuery('term');
    $results = $this->Users->find('all', [
        **'contain' => ['Profiles'],**'
         **conditions' => ['profile.name LIKE' => $name . '%'],**
        'limit' => 10,
        
        **'fields'=>['id','profile.name']**
    ]);
    //debug($results);

```

What he says now is:

1. {message: “SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘profile.name’ in ‘field list’”,…}

2. code: 500

3. file: “/var/www/html/vendor/cakephp/cakephp/src/Database/Statement/MysqlStatement.php”

4. line: 39

5. message: “SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘profile.name’ in ‘field list’”

6. url: “/users/get-ajax-list?term=test”

---

<div class="post-metadata">

**Author:** ![Herzberg](https://avatars.discourse-cdn.com/v4/letter/h/74df32/32.png) [@Herzberg](https://discourse.cakephp.org/u/Herzberg)\
**Post date:** [September 15, 2021, 9:43pm UTC](https://discourse.cakephp.org/t/autocomplete-not-working-404/9716/8 "2021-09-15T21:43:09Z")

</div>

debug($results);

**APP/Controller/UsersController.php** (line **258** )

object(Cake\ORM\Query) id:0 {’(help)’ =\> ‘This is a Query object, to get the results execute or iterate it.’‘sql’ =\> ‘SELECT Users.id AS Users\_\_id, profile.name AS profile\_\_name FROM users Users LEFT JOIN profiles Profiles ON Users.id = (Profiles.user\_id) LIMIT 10’‘params’ =\> []‘defaultTypes’ =\> [‘Users\_\_id’ =\> ‘integer’,‘Users.id’ =\> ‘integer’,‘id’ =\> ‘integer’,‘Users\_\_email’ =\> ‘string’,‘Users.email’ =\> ‘string’,‘email’ =\> ‘string’,‘Users\_\_password’ =\> ‘string’,‘Users.password’ =\> ‘string’,‘password’ =\> ‘‘Users\_\_created’ =\> ‘datetime’,‘Users.created’ =\> ‘datetime’,‘created’ =\> ‘datetime’,‘Users\_\_modified’ =\> ‘datetime’,‘Users.modified’ =\> ‘datetime’,‘modified’ =\> ‘datetime’,‘Profiles\_\_id’ =\> ‘integer’,‘Profiles.id’ =\> ‘integer’,‘Profiles\_\_user\_id’ =\> ‘integer’,‘Profiles.user\_id’ =\> ‘integer’,‘user\_id’ =\> ‘integer’,‘Profiles\_\_name’ =\> ‘string’,‘Profiles.name’ =\> ‘string’,‘name’ =\>‘Profiles\_\_created’ =\> ‘datetime’,‘Profiles.created’ =\> ‘datetime’,‘Profiles\_\_modified’ =\> ‘datetime’,‘Profiles.modified’ =\> ‘datetime’,‘Profiles\_\_country\_id’ =\> ‘integer’,‘Profiles.country\_id’ =\> ‘integer’,]‘decorators’ =\> (int) 0’executed’ =\> false’hydrate’ =\> true’buffered’ =\> true’formatters’ =\> (int) 0’mapReducers’ =\> (int) 0’contain’ =\> [‘Profiles’ =\> [],]‘matching’ =\> []‘extraOptions’ =\> [’ conditions’ =\> [‘profile.name LIKE’ =\> ‘test%’,],]‘repository’ =\> object(App\Model\Table\UsersTable) id:1 {‘registryAlias’ =\> ‘Users’‘table’ =\> ‘users’‘alias’ =\> ‘Users’‘entityClass’ =\> ‘App\Model\Entity\User’‘associations’ =\> [(int) 0 =\> 'Profiles[(int) 0 =\> ‘Timestamp’,]‘defaultConnection’ =\> ‘default’‘connectionName’ =\> ‘default’}}

[**Warning** (512)](javascript:void(0);): Unable to emit headers. Headers sent in file=/var/www/html//vendor/cakephp/cakephp/src/Error/Debugger.php line=1030 [**CORE/src/Http/ResponseEmitter.php** , line **71**]

[**Warning** (2)](javascript:void(0);): Cannot modify header information - headers already sent by (output started at /var/www/html//vendor/cakephp/cakephp/src/Error/Debugger.php:1030) [**CORE/src/Http/ResponseEmitter.php** , line **168**]

[**Warning** (2)](javascript:void(0);): Cannot modify header information - headers already sent by (output started at /var/www/html//vendor/cakephp/cakephp/src/Error/Debugger.php:1030) [**CORE/src/Http/ResponseEmitter.php** , line **197**]

[**Warning** (2)](javascript:void(0);): Cannot modify header information - headers already sent by (output started at /var/www/html//vendor/cakephp/cakephp/src/Error/Debugger.php:1030) [**CORE/src/Http/ResponseEmitter.php** , line **197**]

{ “message”: “SQLSTATE[42S22]: Column not found: 1054 Unknown column \u0027profile.name\u0027 in \u0027field list\u0027”, “url”: “/users/get-ajax-list?term=test”, “code”: 500, “file”: “/var/www/html\/vendor/cakephp/cakephp/src/Database/Statement/MysqlStatement.php”, “line”: 39 }

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [September 15, 2021, 11:28pm UTC](https://discourse.cakephp.org/t/autocomplete-not-working-404/9716/9 "2021-09-15T23:28:54Z")

</div>

The function prototype is `canGetAjaxList(IdentityInterface $user, User $resource)`. The `$user` passed here does _not_ come from your function call, it comes from the authentication system. The thing that you pass to your `authorize` call comes into this function in the `$resource` parameter, and, as I said, is the thing that it checks access _to_, not the user it’s checking access _for_.

In your conditions, you need to use Profiles.name, not profile.name. It is aliasing the table name here, in case there might be a join of the table to itself, for example.

---

<div class="post-metadata">

**Author:** ![Herzberg](https://avatars.discourse-cdn.com/v4/letter/h/74df32/32.png) [@Herzberg](https://discourse.cakephp.org/u/Herzberg)\
**Post date:** [September 15, 2021, 11:48pm UTC](https://discourse.cakephp.org/t/autocomplete-not-working-404/9716/10 "2021-09-15T23:48:07Z")

</div>

works without errors:

1. Request Method:GET
2. Status Code:200 OK

but :

1. {label: null, value: null}, {label: null, value: null}, {label: null, value: null},…]

2. 0: {label: null, value: null}

3. 1: {label: null, value: null}

4. 2: {label: null, value: null}

5. 3: {label: null, value: null}

6. 4: {label: null, value: null}

7. 5: {label: null, value: null}

8. 6: {label: null, value: null}

9. 7: {label: null, value: null}

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [September 15, 2021, 11:53pm UTC](https://discourse.cakephp.org/t/autocomplete-not-working-404/9716/11 "2021-09-15T23:53:14Z")

</div>

Sounds like the problem now is with building the output. I assume that code has changed some since your original post, as you’re now looking at profile names where before it wasn’t. `debug($results)` will just show you the Query object, but `debug($results->toArray())` will be the actual records, and should shed some light on how you need to go about creating your JSON array.

---

<div class="post-metadata">

**Author:** ![Herzberg](https://avatars.discourse-cdn.com/v4/letter/h/74df32/32.png) [@Herzberg](https://discourse.cakephp.org/u/Herzberg)\
**Post date:** [September 16, 2021, 12:10am UTC](https://discourse.cakephp.org/t/autocomplete-not-working-404/9716/12 "2021-09-16T00:10:52Z")

</div>

well i dont know why but now there is even an error again:

code:

index.php

```
<?= $this->Form->create(null,['type'=>'get']) ?>
<?= $this->Form->control('key',['label' => 'Search','value'=>$this->request->getQuery('key')]) ?>
<?= $this->Form->control('profile.name', ['type' => 'text', 'autocomplete' => 'off']); ?>
<?= $this->Form->submit() ?>
<?= $this->Form->end() ?>

```

javascript:  
$(document).ready(function(){

```
jQuery('#profile-name').autocomplete({
    source:'<?= $this->Url->build(["controller" => "Users", "action" => "getAjax-list"],["fullBase" => true,]); ?>',
    minLength: 2,
    delay:0,
    select: function(event, ui) {
            event.preventDefault();
            $("profile.name").val(ui.item.label);
    },

    focus: function(event, ui) {
            event.preventDefault();
            $("#profile.name").val(ui.item.label);
    }
});

```

});

Controller:

public function getAjaxList()  
{  
$this-\>autoRender = false;

```
if ($this->request->is('ajax')) {
    
    $this->Authorization->skipAuthorization();
      
    $name = $this->request->getQuery('term');
    $results = $this->Users->find('all', [
        'contain' => ['Profiles'], '
         conditions' => ['Profiles.name LIKE' => $name . '%'],
        'limit' => 10,
      
        'fields'=>['id','Profiles.name']
    ]);
   // debug($results);
    debug($results->toArray());
        
    $resultsArr = [];
    
    foreach ($results as $result) {
        $resultsArr[] =['label' => $result['Profiles.name'], 'value' => $result['id']];
    }
    
    return $this->response->withType('application/json')->withStringBody(json_encode($resultsArr));
}

```

}

it says:

APP/Controller/UsersController.php (line 259)  
[  
(int) 0 =\> object(App\Model\Entity\User) id:0 {  
‘id’ =\> (int) 6  
‘profile’ =\> object(App\Model\Entity\Profile) id:1 {  
‘name’ =\> ‘james’  
‘[new]’ =\> false  
‘[accessible]’ =\> [  
‘user\_id’ =\> true,  
‘name’ =\> true,  
‘created’ =\> true,  
‘modified’ =\> true,  
‘user’ =\> true,  
]  
‘[dirty]’ =\> [  
]  
‘[original]’ =\> [  
]  
‘[virtual]’ =\> [  
]  
‘[hasErrors]’ =\> false  
‘[errors]’ =\> [  
]  
‘[invalid]’ =\> [  
]  
‘[repository]’ =\> ‘Profiles’  
}  
‘[new]’ =\> false  
‘[accessible]’ =\> [  
‘_’ =\> true,  
‘id’ =\> false,  
‘profile’ =\> true,  
]  
‘[dirty]’ =\> [  
]  
‘[original]’ =\> [  
]  
‘[virtual]’ =\> [  
]  
‘[hasErrors]’ =\> false  
‘[errors]’ =\> [  
]  
‘[invalid]’ =\> [  
]  
‘[repository]’ =\> ‘Users’  
},  
(int) 1 =\> object(App\Model\Entity\User) id:2 {  
‘id’ =\> (int) 7  
‘profile’ =\> object(App\Model\Entity\Profile) id:3 {  
‘name’ =\> ‘tester’  
‘[new]’ =\> false  
‘[accessible]’ =\> [  
‘user\_id’ =\> true,  
‘name’ =\> true,  
‘created’ =\> true,  
‘modified’ =\> true,  
‘user’ =\> true,  
]  
‘[dirty]’ =\> [  
]  
‘[original]’ =\> [  
]  
‘[virtual]’ =\> [  
]  
‘[hasErrors]’ =\> false  
‘[errors]’ =\> [  
]  
‘[invalid]’ =\> [  
]  
‘[repository]’ =\> ‘Profiles’  
}  
‘[new]’ =\> false  
‘[accessible]’ =\> [  
'_’ =\> true,  
‘id’ =\> false,  
‘profile’ =\> true,  
]  
‘[dirty]’ =\> [  
]  
‘[original]’ =\> [  
]  
‘[virtual]’ =\> [  
]  
‘[hasErrors]’ =\> false  
‘[errors]’ =\> [  
]  
‘[invalid]’ =\> [  
]  
‘[repository]’ =\> ‘Users’  
},  
(int) 2 =\> object(App\Model\Entity\User) id:4 {  
‘id’ =\> (int) 8  
‘profile’ =\> object(App\Model\Entity\Profile) id:5 {  
‘name’ =\> ‘rex’  
‘[new]’ =\> false  
‘[accessible]’ =\> [  
‘user\_id’ =\> true,  
‘name’ =\> true,  
‘created’ =\> true,  
‘modified’ =\> true,  
‘user’ =\> true,  
]  
‘[dirty]’ =\> [  
]  
‘[original]’ =\> [  
]  
‘[virtual]’ =\> [  
]  
‘[hasErrors]’ =\> false  
‘[errors]’ =\> [  
]  
‘[invalid]’ =\> [  
]  
‘[repository]’ =\> ‘Profiles’  
}  
‘[new]’ =\> false  
‘[accessible]’ =\> [  
‘_’ =\> true,  
‘id’ =\> false,  
‘profile’ =\> true,  
]  
‘[dirty]’ =\> [  
]  
‘[original]’ =\> [  
]  
‘[virtual]’ =\> [  
]  
‘[hasErrors]’ =\> false  
‘[errors]’ =\> [  
]  
‘[invalid]’ =\> [  
]  
‘[repository]’ =\> ‘Users’  
},  
(int) 3 =\> object(App\Model\Entity\User) id:6 {  
‘id’ =\> (int) 1  
‘profile’ =\> object(App\Model\Entity\Profile) id:7 {  
‘name’ =\> ‘testerdasd’  
‘[new]’ =\> false  
‘[accessible]’ =\> [  
‘user\_id’ =\> true,  
‘name’ =\> true,  
‘created’ =\> true,  
‘modified’ =\> true,  
‘user’ =\> true,  
]  
‘[dirty]’ =\> [  
]  
‘[original]’ =\> [  
]  
‘[virtual]’ =\> [  
]  
‘[hasErrors]’ =\> false  
‘[errors]’ =\> [  
]  
‘[invalid]’ =\> [  
]  
‘[repository]’ =\> ‘Profiles’  
}  
‘[new]’ =\> false  
‘[accessible]’ =\> [  
'_’ =\> true,  
‘id’ =\> false,  
‘profile’ =\> true,  
]  
‘[dirty]’ =\> [  
]  
‘[original]’ =\> [  
]  
‘[virtual]’ =\> [  
]  
‘[hasErrors]’ =\> false  
‘[errors]’ =\> [  
]  
‘[invalid]’ =\> [  
]  
‘[repository]’ =\> ‘Users’  
},  
(int) 4 =\> object(App\Model\Entity\User) id:8 {  
‘id’ =\> (int) 2  
‘profile’ =\> object(App\Model\Entity\Profile) id:9 {  
‘name’ =\> ‘tesddter’  
‘[new]’ =\> false  
‘[accessible]’ =\> [  
‘user\_id’ =\> true,  
‘name’ =\> true,  
‘created’ =\> true,  
‘modified’ =\> true,  
‘user’ =\> true,  
]  
‘[dirty]’ =\> [  
]  
‘[original]’ =\> [  
]  
‘[virtual]’ =\> [  
]  
‘[hasErrors]’ =\> false  
‘[errors]’ =\> [  
]  
‘[invalid]’ =\> [  
]  
‘[repository]’ =\> ‘Profiles’  
}  
‘[new]’ =\> false  
‘[accessible]’ =\> [  
‘_’ =\> true,  
‘id’ =\> false,  
‘profile’ =\> true,  
]  
‘[dirty]’ =\> [  
]  
‘[original]’ =\> [  
]  
‘[virtual]’ =\> [  
]  
‘[hasErrors]’ =\> false  
‘[errors]’ =\> [  
]  
‘[invalid]’ =\> [  
]  
‘[repository]’ =\> ‘Users’  
},  
(int) 5 =\> object(App\Model\Entity\User) id:10 {  
‘id’ =\> (int) 3  
‘profile’ =\> object(App\Model\Entity\Profile) id:11 {  
‘name’ =\> ‘tefarster’  
‘[new]’ =\> false  
‘[accessible]’ =\> [  
‘user\_id’ =\> true,  
‘name’ =\> true,  
‘created’ =\> true,  
‘modified’ =\> true,  
‘user’ =\> true,  
]  
‘[dirty]’ =\> [  
]  
‘[original]’ =\> [  
]  
‘[virtual]’ =\> [  
]  
‘[hasErrors]’ =\> false  
‘[errors]’ =\> [  
]  
‘[invalid]’ =\> [  
]  
‘[repository]’ =\> ‘Profiles’  
}  
‘[new]’ =\> false  
‘[accessible]’ =\> [  
'_’ =\> true,  
‘id’ =\> false,  
‘profile’ =\> true,  
]  
‘[dirty]’ =\> [  
]  
‘[original]’ =\> [  
]  
‘[virtual]’ =\> [  
]  
‘[hasErrors]’ =\> false  
‘[errors]’ =\> [  
]  
‘[invalid]’ =\> [  
]  
‘[repository]’ =\> ‘Users’  
},  
(int) 6 =\> object(App\Model\Entity\User) id:12 {  
‘id’ =\> (int) 4  
‘profile’ =\> object(App\Model\Entity\Profile) id:13 {  
‘name’ =\> ‘michel’  
‘[new]’ =\> false  
‘[accessible]’ =\> [  
‘user\_id’ =\> true,  
‘name’ =\> true,  
‘created’ =\> true,  
‘modified’ =\> true,  
‘user’ =\> true,  
]  
‘[dirty]’ =\> [  
]  
‘[original]’ =\> [  
]  
‘[virtual]’ =\> [  
]  
‘[hasErrors]’ =\> false  
‘[errors]’ =\> [  
]  
‘[invalid]’ =\> [  
]  
‘[repository]’ =\> ‘Profiles’  
}  
‘[new]’ =\> false  
‘[accessible]’ =\> [  
‘_’ =\> true,  
‘id’ =\> false,  
‘profile’ =\> true,  
]  
‘[dirty]’ =\> [  
]  
‘[original]’ =\> [  
]  
‘[virtual]’ =\> [  
]  
‘[hasErrors]’ =\> false  
‘[errors]’ =\> [  
]  
‘[invalid]’ =\> [  
]  
‘[repository]’ =\> ‘Users’  
},  
(int) 7 =\> object(App\Model\Entity\User) id:14 {  
‘id’ =\> (int) 5  
‘profile’ =\> object(App\Model\Entity\Profile) id:15 {  
‘name’ =\> ‘sebi’  
‘[new]’ =\> false  
‘[accessible]’ =\> [  
‘user\_id’ =\> true,  
‘name’ =\> true,  
‘created’ =\> true,  
‘modified’ =\> true,  
‘user’ =\> true,  
]  
‘[dirty]’ =\> [  
]  
‘[original]’ =\> [  
]  
‘[virtual]’ =\> [  
]  
‘[hasErrors]’ =\> false  
‘[errors]’ =\> [  
]  
‘[invalid]’ =\> [  
]  
‘[repository]’ =\> ‘Profiles’  
}  
‘[new]’ =\> false  
‘[accessible]’ =\> [  
'_’ =\> true,  
‘id’ =\> false,  
‘profile’ =\> true,

]  
‘[dirty]’ =\> [  
]  
‘[original]’ =\> [  
]  
‘[virtual]’ =\> [  
]  
‘[hasErrors]’ =\> false  
‘[errors]’ =\> [  
]  
‘[invalid]’ =\> [  
]  
‘[repository]’ =\> ‘Users’  
},  
]  
Warning (512): Unable to emit headers. Headers sent in file=/var/www/html//vendor/cakephp/cakephp/src/Error/Debugger.php line=1030 [CORE/src/Http/ResponseEmitter.php, line 71]  
Warning (2): Cannot modify header information - headers already sent by (output started at /var/www/html//vendor/cakephp/cakephp/src/Error/Debugger.php:1030) [CORE/src/Http/ResponseEmitter.php, line 168]  
Warning (2): Cannot modify header information - headers already sent by (output started at /var/www/html//vendor/cakephp/cakephp/src/Error/Debugger.php:1030) [CORE/src/Http/ResponseEmitter.php, line 197]  
Warning (2): Cannot modify header information - headers already sent by (output started at /var/www/html//vendor/cakephp/cakephp/src/Error/Debugger.php:1030) [CORE/src/Http/ResponseEmitter.php, line 197][{“label”:null,“value”:6},{“label”:null,“value”:7},{“label”:null,“value”:8},{“label”:null,“value”:1},{“label”:null,“value”:2},{“label”:null,“value”:3},{“label”:null,“value”:4},{“label”:null,“value”:5}]

---

<div class="post-metadata">

**Author:** ![Herzberg](https://avatars.discourse-cdn.com/v4/letter/h/74df32/32.png) [@Herzberg](https://discourse.cakephp.org/u/Herzberg)\
**Post date:** [September 16, 2021, 12:17am UTC](https://discourse.cakephp.org/t/autocomplete-not-working-404/9716/13 "2021-09-16T00:17:04Z")

</div>

error comes from the debug… but its not wotking anyway

---

<div class="post-metadata">

**Author:** ![Herzberg](https://avatars.discourse-cdn.com/v4/letter/h/74df32/32.png) [@Herzberg](https://discourse.cakephp.org/u/Herzberg)\
**Post date:** [September 16, 2021, 12:21am UTC](https://discourse.cakephp.org/t/autocomplete-not-working-404/9716/14 "2021-09-16T00:21:39Z")

</div>

sorry index.php and javascirpt are looking like that now:

index.php  
\<?= $this-\>Form-\>control('profiles.name', ['type' =\> 'text', 'autocomplete' =\> 'off']); ?\>

javascript:

$(document).ready(function(){

```
jQuery('#profiles-name').autocomplete({
    source:'<?= $this->Url->build(["controller" => "Users", "action" => "getAjax-list"],["fullBase" => true,]); ?>',
    minLength: 2,
    delay:0,
    select: function(event, ui) {
            event.preventDefault();
            $("profiles.name").val(ui.item.label);
    },

    focus: function(event, ui) {
            event.preventDefault();
            $("#profiles.name").val(ui.item.label);
    }
});

```

});

response is still:

1. [{label: null, value: 6}, {label: null, value: 7}, {label: null, value: 8}, {label: null, value: 1},…]

2. 0: {label: null, value: 6}

3. 1: {label: null, value: 7}

4. 2: {label: null, value: 8}

5. 3: {label: null, value: 1}

6. 4: {label: null, value: 2}

7. 5: {label: null, value: 3}

8. 6: {label: null, value: 4}

9. 7: {label: null, value: 5}

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [September 16, 2021, 12:28am UTC](https://discourse.cakephp.org/t/autocomplete-not-working-404/9716/15 "2021-09-16T00:28:55Z")

</div>

Try:

```auto
$resultsArr[] =['label' => $result->profile->name, 'value' => $result->id];

```

This is pretty obvious once you are familiar with reading the debug output. Get used to Cake’s conventions around how to name tables (`profiles`) and associations (`Profiles`), how to reference them in queries (`Profiles.field_name`), and how to access the resulting properties (`$entity->profile` is the one profile when it’s a `belongsTo` or `hasOne` association; `$entity->profiles` is an array of profiles when it’s a `hasMany` or `belongsToMany` association).

---

<div class="post-metadata">

**Author:** ![Herzberg](https://avatars.discourse-cdn.com/v4/letter/h/74df32/32.png) [@Herzberg](https://discourse.cakephp.org/u/Herzberg)\
**Post date:** [September 16, 2021, 12:33am UTC](https://discourse.cakephp.org/t/autocomplete-not-working-404/9716/16 "2021-09-16T00:33:16Z")

</div>

now it shows the names but it just shows everything:

1. [{label: “james”, value: 6}, {label: “tester”, value: 7}, {label: “rex”, value: 8},…]

2. 0: {label: “james”, value: 6}

3. 1: {label: “tester”, value: 7}

4. 2: {label: “rex”, value: 8}

5. 3: {label: “testerdasd”, value: 1}

6. 4: {label: “tesddter”, value: 2}

7. 5: {label: “tefarster”, value: 3}

8. 6: {label: “michel”, value: 4}

9. 7: {label: “sebi”, value: 5}

if i say limit to 1 it still shows james on the first position even if i write michel and if i click on a name on the list it not even use it. i cant select it

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [September 16, 2021, 1:28am UTC](https://discourse.cakephp.org/t/autocomplete-not-working-404/9716/17 "2021-09-16T01:28:53Z")

</div>

Presumably, the `term` query string is not being sent for some reason. That falls squarely into the jQuery side of things, nothing to do with Cake.

---

<div class="post-metadata">

**Author:** ![Herzberg](https://avatars.discourse-cdn.com/v4/letter/h/74df32/32.png) [@Herzberg](https://discourse.cakephp.org/u/Herzberg)\
**Post date:** [September 16, 2021, 2:09pm UTC](https://discourse.cakephp.org/t/autocomplete-not-working-404/9716/18 "2021-09-16T14:09:26Z")

</div>

but if I use debug i get:

‘extraOptions’ =\> [  
’  
conditions’ =\> [  
‘Profiles.name LIKE’ =\> ‘test%’,  
],  
]

test is what i was entering into the input field…

with debug i get warnings:

[**Warning** (512)](javascript:void(0);): Unable to emit headers. Headers sent in file=/var/www/html//vendor/cakephp/cakephp/src/Error/Debugger.php line=1030 [**CORE/src/Http/ResponseEmitter.php** , line **71**]

[**Warning** (2)](javascript:void(0);): Cannot modify header information - headers already sent by (output started at /var/www/html/r/vendor/cakephp/cakephp/src/Error/Debugger.php:1030) [**CORE/src/Http/ResponseEmitter.php** , line **168**]

[**Warning** (2)](javascript:void(0);): Cannot modify header information - headers already sent by (output started at /var/www/html//vendor/cakephp/cakephp/src/Error/Debugger.php:1030) [**CORE/src/Http/ResponseEmitter.php** , line **197**]

[**Warning** (2)](javascript:void(0);): Cannot modify header information - headers already sent by (output started at /var/www/html/vendor/cakephp/cakephp/src/Error/Debugger.php:1030) [**CORE/src/Http/ResponseEmitter.php** , line **197**]

[{“label”:“james”,“value”:6,“job”:"asd "},{“label”:“tester”,“value”:7,“job”:“maurer”},{“label”:“rex”,“value”:8,“job”:“maurer”},{“label”:“testerdasd”,“value”:1,“job”:"asd "},{“label”:“tesddter”,“value”:2,“job”:"asd "},{“label”:“tefarster”,“value”:3,“job”:“maurer”},{“label”:“michel”,“value”:4,“job”:"asd "},{“label”:“sebi”,“value”:5,“job”:"asd "}]

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [September 16, 2021, 5:15pm UTC](https://discourse.cakephp.org/t/autocomplete-not-working-404/9716/19 "2021-09-16T17:15:40Z")

</div>

What does `debug($results->sql());` give you? (You can safely ignore all of the “Cannot modify header” warnings, as those are entirely to be expected based on the fact that you’re generating debug output.)

---

<div class="post-metadata">

**Author:** ![Herzberg](https://avatars.discourse-cdn.com/v4/letter/h/74df32/32.png) [@Herzberg](https://discourse.cakephp.org/u/Herzberg)\
**Post date:** [September 16, 2021, 5:40pm UTC](https://discourse.cakephp.org/t/autocomplete-not-working-404/9716/20 "2021-09-16T17:40:34Z")

</div>

**APP/Controller/UsersController.php** (line **260** )

‘SELECT Profiles.name AS Profiles\_\_name, Users.id AS Users\_\_id, FROM users Users LEFT JOIN profiles Profiles ON Users.id = (Profiles.user\_id) LIMIT 10’

the condition is missing

[Next page](https://discourse.cakephp.org/t/autocomplete-not-working-404/9716.md?page=2)
