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}]