如何解决使用Cakephp 3实现自动完成时出错
朋友,我正在尝试为Cakephp 3.8中的项目改编this tutorial。我有一个用户表,我想按名称进行搜索。
使用烘焙生成代码并插入搜索字段后,我的index.ctp如下所示:
<html>
<body>
<?= $this->Form->create('',['type' => 'get']); ?>
<?= $this->Form->control('keyword',array('class' => 'auto','value' => '','label' => false,'required' => true));?>
<?= $this->Form->button(__('Search')); ?>
<?= $this->Form->end(); ?>
<nav class="large-3 medium-4 columns" id="actions-sidebar">
<ul class="side-nav">
<li class="heading"><?= __('Actions') ?></li>
<li><?= $this->Html->link(__('New User'),['action' => 'add']) ?></li>
</ul>
</nav>
<div class="large-9 medium-8 columns content">
<h3><?= __('Users') ?></h3>
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
<th scope="col"><?= $this->Paginator->sort('id') ?></th>
<th scope="col"><?= $this->Paginator->sort('name') ?></th>
<th scope="col"><?= $this->Paginator->sort('created') ?></th>
<th scope="col" class="actions"><?= __('Actions') ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($users as $user): ?>
<tr>
<td><?= $this->Number->format($user->id) ?></td>
<td><?= h($user->nome) ?></td>
<td><?= h($user->created) ?></td>
<td class="actions">
<?= $this->Html->link(__('View'),['action' => 'view',$user->id]) ?>
<?= $this->Html->link(__('Edit'),['action' => 'edit',$user->id]) ?>
<?= $this->Form->postLink(__('Delete'),['action' => 'delete',$user->id],['confirm' => __('Are you sure you want to delete # {0}?',$user->id)]) ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div class="paginator">
<ul class="pagination">
<?= $this->Paginator->first('<< ' . __('first')) ?>
<?= $this->Paginator->prev('< ' . __('previous')) ?>
<?= $this->Paginator->numbers() ?>
<?= $this->Paginator->next(__('next') . ' >') ?>
<?= $this->Paginator->last(__('last') . ' >>') ?>
</ul>
<p><?= $this->Paginator->counter(['format' => __('Page {{page}} of {{pages}},showing {{current}} record(s) out of {{count}} total')]) ?>
</p>
</div>
</div>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.1/jquery-ui.min.js"></script>
<script type="text/javascript">
$(function() {
$(".auto").autocomplete({
source: "/users",minLength: 1
});
});
</script>
</body>
</html>
在这部分中,我不知道如何适应。
//autocomplete
$(".auto").autocomplete({
source: "users",minLength: 1
});
在这部分中,我不知道该如何适应。
我的UsersController.php看起来像这样:
public function index()
{
$users= $this->paginate = [
'conditions' => [
'name like' => '%'. $this->request->getQuery('keyword') . '%',]
];
$this->set('users',$this->paginate($this->Users));
$this->set('_serialize',['users']);
}
此刻,对于任何搜索,即使该名称存在于数据库中,我也会得到“没有搜索结果。”。 我感谢有人可以分析。欢迎发表评论!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。