繁体   English   中英

返回全文搜索结果

[英]Returning full text search results

我正在关注本教程:

http://creative-punch.net/2013/12/implementing-laravel-4-full-text-search

我通过适应我自己的项目来遵循它,我的问题是如何显示查询的结果谢谢

代码如下:

<!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'
   )
  );

 ?>

好的,在这里我会做一些假设,所以您可能需要稍微修改一下代码以满足您的需求...

首先,您当然不需要将ec2_instance传递给视图,而是将结果传递给$posts

return View::make('ec2_instance.search', compact('posts'));

现在,由于您的结果将是帖子的集合,因此您需要在视图中对其进行循环:

ec2_instance.search

@foreach($posts as $post)
    {{-- display properties here --}}
    {{ $post->key_name }}
    {{-- etc... --}}
@endforeach

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM