2015-01-01 107 views
0

,所以這是我的控制器:搜索引擎不能正常工作+功能

 class PostsController extends BaseController 
    { 
     public function postSearch() 
     { 
     $q = Input::get('username'); 

     $posts = DB::table('users')->whereRaw(
      "MATCH(username) AGAINST(? IN BOOLEAN MODE)", 
      array($q) 
     )->get(); 

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

    } 


} 

和我的路線:

Route::get('posts/index', function() 
{ 
    return View::make('posts/index'); 
}); 


Route::post(
    ''posts/index', 
    array(
     'as' => 'posts.index', 
     'uses' => '[email protected]' 
    ) 


); 

和我的html:

<div class="search"> 
    {{ Form::model(null, array('route' => array('posts.index'))) }} 
    {{ Form::text('username', null, array('placeholder' => 'Search query...')) }} 
    {{ Form::submit('Search') }} 
    {{ Form::close() }} 


</div> 

的問題是,它給我錯誤:

MethodNotAllowedHttpException 

所以我不能讓用戶能夠在索引頁中進行搜索,並將結果顯示在表中的不同頁面中 我如何才能使結果顯示以及此錯誤是什麼?

回答

0

您正在盡一切正常,但在路由文件類被命名爲PostsController,但實際控制人的類名是postController這就是爲什麼它說PostsController沒有找到。

路線:

Route::get('posts/index', function() 
{ 
    return View::make('posts/index'); 
}); 

Route::post('posts/index', array('as' => 'posts.index','uses' => '[email protected]')); 

控制器

class PostsController extends BaseController 
{ 
    public function postSearch() 
    { 
     $q = Input::get('username'); 

     $posts = DB::table('users')->whereRaw(
      "MATCH(username) AGAINST(? IN BOOLEAN MODE)", 
      array($q) 
     )->get(); 

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

    } 
} 

查看

<div class="search"> 
    {{ Form::open(array('route' => 'post.index', 'method' => 'POST', 'role' => 'search')) }} 
    {{ Form::text('username',null, array('placeholder' => 'Search query...')) }} 
    {{ Form::submit('Search') }} 
    {{ Form::close() }} 
</div> 

@if(isset($posts)) 

@foreach($posts as $post) 

{{$post->id}} 

@endforeach 

@endif 
+0

我已經改變了我的{{表::打開(陣列( 'URL' >'登錄','class'= >'form-horizo​​ntal'))}} 你說的,但它給了我同樣的錯誤:( – Greatone

+1

你改變了你的控制器類名? 'postController'到'PostsController'? –

+0

編輯了開放的帖子,新的錯誤:( – Greatone