控制器:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Test extends CI_Controller
{
function __construct()
{
parent :: __construct();
$this->load->helper(array('form', 'url'));
$this->load->model('select');
}
public function index()
{
$this->load->view('index');
if(isset($_GET['term'])){
$location = strtolower($_GET['term']);
echo $this->select->autoload($college_name);
}
}
}
观点:
<link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$( "#colleges" ).autocomplete({
source: function(request, response) {
$.ajax({
url: "http://localhost/collegescan_ci/index.php/test/search",
data: { term: $("#colleges").val()},
dataType: "json",
type: "POST",
success: function(data){
var resp = $.map(data,function(obj){
return obj.college_name;
});
response(resp);
}
});
},
minLength: 2
});
});
</script>
<input type="text" name="colleges" id="colleges"/>
模型:
<?php
class Select extends CI_Model{
public function autoload($term)
{
$query = $this->db->query("SELECT college_name FROM all_colleges where college_name like '%".$term."%' ORDER BY CASE WHEN short_name LIKE '%".$term."%' THEN 1 ELSE 2 END");
echo json_encode($query->result_array());
}
}
我是codeigniter的新手,我想创建一个自动完成文本框。在这段代码中,我创建了一个自动完成文本框,但它无效。我不知道为什么?请有人帮帮我。
谢谢
答案 0 :(得分:0)
请遵循codeigntor手册。根据codeigntor手册,型号名称应该是这样的&#39; Yourmodelname_model&#39;也不确定您是否可以将型号命名为&#39;选择&#39;,
<div class="parent">
<div class="child">
<div class="non-shadowed-div">
This div shouldn't be shadowed like the rest of the square
</div>
</div>
</div>
请参考codeigntor giude,