I am new in CodeIgniter and I am trying to build a basic search engine using JQuery.
My controler is
class Welcome extends CI_Controller {
public function index()
{
$this->load->view('searchPeople');
$this->load->view('css/format');
}
public function searchPeopleResults(){
$theCity=$_POST['theCity'];
$this->load->model('MSearchPeople');
$data=$this->MSearchPeople->provideSearchPeopleResults($theCity);
$this->load->view('searchPeople',$data);
$this->load->view('css/format');
}
}
The relevant part of my model is
Class MSearchPeople extends Model {
function MSearchPeople() {
parent::Model();
}
function provideSearchPeopleResults($theCity){
// ... There is a query to the database that I dinamically generate HTML data.
return $data;
}
The relevant part of my view is
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.3.2.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.1.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("form#searchForm").submit(function() {
var theCity = $("select#chooseCity").val();
$.post("welcome/searchPeopleResults/", {theCity: theCity}, function(data) {
$("div#searchResults").html(data);
});
return false
});
});
</script>
</head>
<body>
<FORM id="searchForm">
<h2>Selecione uma cidade: </h2>
<select id="chooseCity">
<?php
$theCitiesOptionsHTML = "cityOptions.html"; <!-- A large list of cities -->
require($thePathDataFiles.$theCitiesOptionsHTML);
?>
</select>
</FORM>
<div id="searchResults">
<!-- Search results should arise here -->
</div>
</body>
</html>
It is important to stress that the version without the MVC design in PHP is working. However, after translating this, it is not working anymore.
}
The netbeans output is:
[Mon Feb 10 01:06:19 2014] 127.0.0.1:52977 [200]: /
[Mon Feb 10 01:06:29 2014] 127.0.0.1:52980 [500]: /welcome/searchPeopleResults/
[Mon Feb 10 01:06:29 2014] 127.0.0.1:52981 [500]: /welcome/searchPeopleResults/
**1) Are there necessary two controllers "index" and "searchPeopleResults"?
2) Is the data correctly transfered to the necessary classes?
3) Is there anyway to echo the variables inside these class?**
4) Should I load something besides the scripts in the above-mentioned head?
Thank you!