我正在学习本教程:
http://creative-punch.net/2013/12/implementing-laravel-4-full-text-search
我通过适应我自己的项目来跟踪它,我的问题是如何显示我所查询的结果谢谢
代码如下:view
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Laravel PHP Framework</title>
<style>
@import url(//fonts.googleapis.com/css?family=Lato:700);
body {
margin:0;
font-family:'Lato', sans-serif;
text-align:center;
color: #999;
}
.welcome {
width: 300px;
height: 200px;
position: absolute;
left: 50%;
top: 50%;
margin-left: -150px;
margin-top: -100px;
}
a, a:visited {
text-decoration:none;
}
h1 {
font-size: 32px;
margin: 16px 0 0 0;
}
</style>
</head>
<body>
<div class="search">
{{ Form::model(null, array('route' => array('ec2_instance.search'))) }}
{{ Form::text('query', null, array( 'placeholder' => 'Search query...' )) }}
{{ Form::submit('Search') }}
{{ Form::close() }}
</div>
</body>
</html>
我的控制员:
<?php
class PostsController extends BaseController {
public function postSearch(){
$q = Input::get('query');
$posts = ec2_instance::whereRaw("MATCH(instance_id,instance_type,availability_zone, status_checks,alarm_status, public_dns, key_name ) AGAINST(? IN BOOLEAN MODE)",
array($q))->get();
return View::make('ec2_instance.search', compact('ec2_instance'));
}
}
?>
我的路线:
Route::get('/', function()
{
return View::make('search');
});
Route::post(
'ec2_instance/search',
array(
' as' => 'ec2_instance.search',
'uses' => 'PostsController@postSearch'
)
);
?>
答案 0 :(得分:0)
好的我会在这里做一些假设,所以你可能需要改变一些代码来满足你的需求......
首先,你当然不需要将ec2_instance
传递给视图,而是将结果传递给$posts
return View::make('ec2_instance.search', compact('posts'));
现在,由于您的结果将是一组帖子,您需要在视图中循环显示:
@foreach($posts as $post)
{{-- display properties here --}}
{{ $post->key_name }}
{{-- etc... --}}
@endforeach