- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我的网站上有一个表格,可以在其中提交一只猫。该表单包含“姓名”和“性别”等输入,但我只是想让自动完成功能与“姓名”字段一起使用。这是我的 jquery 的样子:
$(document).ready(function() {
$( "#tags" ).autocomplete({
source: '/Anish/auto_cat'
});
});
这是我的模型的样子:
public function auto_cat($search_term) {
$this->db->like('name', $search_term);
$response = $this->db->get('anish_cats')->result_array();
// var_dump($response);die;
return $response;
}
}
这是我的 Controller :
public function auto_cat(){
$search_term = $this->input->get('term');
$cats = $this->Anish_m->auto_cat($search_term);
}
这是我的观点:
<head>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
</head>
<h1>Anish's Page</h1>
<form action="/Anish/create" method="POST">
<div class="ui-widget">
<label for="tags">Name</label><input id="tags" type="text" name="name">
</div>
<div>
<label>Age</label><input type="text" name="age">
</div>
<div>
<label>Gender</label><input type="text" name="gender">
</div>
<div>
<label>Species</label><input type="text" name="species">
</div>
<div>
<label>Eye Color</label><input type="text" name="eye_color">
</div>
<div>
<label>Color</label><input type="text" name="color">
</div>
<div>
<label>Description</label><input type="text" name="description">
</div>
<div>
<label>marital status</label><input type="text" name="marital_status">
</div>
<br>
<button type="submit" class="btn btn-block btn-primary span1">Add cat</button>
</form>
<br/><br/><br/><br/>
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>Name</th>
<th>Gender</th>
<th>Age</th>
<th>Species</th>
<th>Eye Color</th>
<th>Color</th>
<th>Description</th>
<th>Marital Status</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php foreach ($cats as $cat):?>
<tr>
<td>
<?php echo ($cat['name']);?><br/>
</td>
<td>
<?php echo ($cat['gender']);?><br/>
</td>
<td>
<?php echo ($cat['age']);?><br/>
</td>
<td>
<?php echo ($cat['species']);?><br/>
</td>
<td>
<?php echo ($cat['eye_color']);?><br/>
</td>
<td>
<?php echo ($cat['color']);?><br/>
</td>
<td>
<?php echo ($cat['description']);?><br/>
</td>
<td>
<?php echo ($cat['marital_status']);?><br/>
</td>
<td>
<form action="/Anish/edit" method="post">
<input type="hidden" value="<?php echo ($cat['id']);?>" name="Anish_id_edit">
<button class="btn btn-block btn-info">Edit</button>
</form>
</td>
<td>
<form action="/Anish/delete" method="post">
<input type="hidden" value="<?php echo ($cat['id']);?>" name="Anish_id">
<button class="btn btn-block btn-danger">Delete</button>
</form>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
我卡住了。在我的控制台中,如果我在我的模型中取消注释 var_dump,那么当我输入字母“a”时,我能够看到这个输出:
array(4) {
[0]=>
array(9) {
["id"]=>
string(2) "13"
["name"]=>
string(5) "Anish"
["gender"]=>
string(4) "Male"
["age"]=>
string(2) "20"
["species"]=>
string(3) "Cat"
["eye_color"]=>
string(5) "Brown"
["color"]=>
string(5) "Black"
["description"]=>
string(7) "Awesome"
["marital_status"]=>
string(1) "0"
}
[1]=>
array(9) {
["id"]=>
string(2) "16"
["name"]=>
string(5) "Anish"
["gender"]=>
string(2) "fe"
["age"]=>
string(2) "23"
["species"]=>
string(2) "fe"
["eye_color"]=>
string(2) "fe"
["color"]=>
string(2) "fe"
["description"]=>
string(2) "fe"
["marital_status"]=>
string(1) "1"
}
[2]=>
array(9) {
["id"]=>
string(2) "17"
["name"]=>
string(1) "a"
["gender"]=>
string(1) "a"
["age"]=>
string(1) "4"
["species"]=>
string(1) "a"
["eye_color"]=>
string(1) "a"
["color"]=>
string(1) "a"
["description"]=>
string(1) "a"
["marital_status"]=>
string(1) "0"
}
[3]=>
array(9) {
["id"]=>
string(2) "18"
["name"]=>
string(4) "Matt"
["gender"]=>
string(6) "Female"
["age"]=>
string(2) "80"
["species"]=>
string(6) "ferret"
["eye_color"]=>
string(4) "blue"
["color"]=>
string(4) "pink"
["description"]=>
string(5) "Chill"
["marital_status"]=>
string(1) "0"
}
}
这是我的 table 的图片:
感谢所有的帮助。
最佳答案
如果有帮助,试试这个:
<?php
#controller function
public function auto_cat(){
print_r ( $this->model->search_auto_cat($_REQUEST['term']) );
}
#model function
function search_auto_cat($term){
$data = array();
$rs = $this->db->select('name as label, name as value, id', false)->or_like('name', $term)->or_like('last_name', $term)->or_like('id', $term)->limit(20)->get('anish_cats');
//print_r($this->db->last_query());
if($rs->num_rows() > 0 ){
$temp = $rs->result_array();
}else{
$temp = array();
$temp[0]['label'] = "No results found";
$temp[0]['value'] = "";
$temp[0]['id'] = "0";
}
$data = json_encode($temp);
return $data;
}
?>
关于jquery - 使用 CodeIgniter (Active Record) 从数据库自动完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17354191/
我想扩展调用 getMessage 时返回自定义消息的异常类。 class MY_Exceptions extends CI_Exceptions{ function __construct
我已经安装了一个干净的 Apache2(加上 PHP 和 MySQL)服务器并启用了 mod_rewrite在 apache 配置中。 我添加了 .htaccess文件以从 url 中删除 index
我正在使用上传类上传图片。但是我上传的图片的存储位置是:http://www.mysite.com/uploads/ 此文件夹的绝对路径是:c:\wamp\www\mysite\uploads\ 应用
大家好 我想在codeigniter上下文中提供一些静态html页面。我不想绕过base_url中的index.php文件。 但是,当我使用对HTML文件的调用时,它不会显示404错误页面。 感谢已经
我一直想知道在模型中以 OO 风格编写代码的正确方法是什么。当然,您可以拥有一个从数据库中检索数据然后映射到模型级变量的函数。但是,当您在模型中有其他功能试图从 BD 获取其他数据时,这种方法会变得违
之前所有的 JOIN 尝试都给我留下了填充结果的 id、标题键的光盘或项目数据(可能发生了冲突)。 所以我有: item table fields: id, title disc table fiel
假设我在 Controller 中有一个名为 的方法 book($chapter,$page); 其中 $chapter 和 $page 必须是整数。要访问该方法,URI 将如下所示 book/cha
我有一个用户可以注册的页面。他在此过程中上传了个人资料照片。我想限制大小,但除了 $config['maxsize'] 之外,并没有太多强调 codeigniter 文档。我尝试了以下但我没有收到任何
我需要将 CodeIgniter 设置为真正的多语言网站。我已经搜索过,但找不到解决方案。 我已经测试了这种方法,但它不起作用。 ( http://codeigniter.com/wiki/Categ
CodeIgniter 中的常量是否可以用于整个站点中的重复文本(比如元标记和元描述)?就像是: define('METADESCRIPTION', 'This is my site'); 然后将 M
我已经在 CodeIgniter 的路由器中写了这个。 $route['companyname'] = "/profile/1"; 这工作正常,但是当我在 URL 中键入“公司名称”时,它不起作用。这
我正在开始我的第一个 CodeIgniter 项目,并希望在开始之前获得一些建议。我对 Controller 和模型的名称如何工作感到有些困惑。 如果我希望我公司页面的网址为 http://examp
可以在CodeIgniter Active Record中使用多个INSERT记录,而无需for,foreach等。 我当前的代码: foreach($tags as $tag) { $tag
SELECT * FROM certs WHERE id NOT IN (SELECT id_cer FROM revokace); 如何在 CodeIgniter 事件记录中编写上述 select
wkhtmltopdf 听起来是一个很好的解决方案...问题是 exec 上没有任何反应 shell_exec("c:\wkhtmltopdf.exe","http://www.google.com
我当前的CodeIgniter有点问题。我有一个带有“页面” Controller 的CI安装程序,该 Controller 可从/ views加载静态文件,但它最多只能包含1个子文件夹,而我正在向其
有一段时间,我一直在处理分页类中的一个问题。 问题是,除了第 1 页的链接之外,所有分页的内容都可以。 所有链接都是这样的: example.com/method/page/2 example.com
我想对请求进行一些预处理和后处理,例如处理身份验证、加载上下文数据、性能时间等等。来自 Django 的概念是 MIDDLEWARE_CLASSES这让我可以在各个阶段处理请求:https://doc
我想通过创建自己的库和配置文件在 CodeIgniter 中生成全局变量。这就是我在我的库文件中编写的,比如说 globalvars.php。我把它放在/application/libraries 中
我有以下分页样式 Previous Page
我是一名优秀的程序员,十分优秀!