所以这是代码:
<?php
class SearchController extends BaseController {
public function getIndex()
{
return View::make('search.index');
}
public function postSearch()
{
$return = array();
$term = Input::get('term');
$books = array(array('name' => 'Alice in Wonderland', 'author' => 'Lewis Carroll'),array('name' => 'Tom Sawyer', 'author' => 'Mark Twain'),array('name' => 'Gulliver\'s Travels', 'author' =>'Jonathan Swift'),array('name' => 'The Art of War', 'author' => 'Sunzi'),array('name' => 'Dracula', 'author' => 'Bram Stoker'),array('name' => 'War and Peace', 'author' =>'LeoTolstoy'),);
foreach ($books as $book) {
if (stripos($book['name'], $term) !== FALSE) $return[] =$book;
}
return Response::json($return);
}
}
?>
这是路线:
Route::controller('search', 'SearchController');
和html:
<div id="results"></div>
<script>
$(function() {
$("#search-form").on("submit", function(e) {e.preventDefault();
var search_term = $("#term").val();
var display_results = $("#results");
display_results.html("loading...");
var results = '';
$.post("search/search", {term: search_term}, function(data) {if (data.length == 0) {results = 'No Results';
} else {
$.each(data, function() {
results += this.name + ' by ' + this.author + '<br>';
});
}
display_results.html(results);
});
})
});
</script>
现在这是错误:
Class SearchController does not exist
一切似乎都没问题,但问题是什么?它找不到我的班级............................................. .................................................. .................................................. .......