2014-01-28 69 views
4

我目前具有Laravel 4.麻煩我想用爲論壇類別和論壇主題蛞蝓(鼻涕蟲是唯一的)。爲了確定的,如果用戶是在一個類別或主題中,我有這樣的路線:Laravel 4重定向::行動()「沒有定義路由」

Route::get('forum/{slug}', function($slug) { 

    $category = ForumCategory::where('slug', '=', $slug)->first(); 

    if (!is_null($category)) 
     return Redirect::action('[email protected]', array('slug' => $slug)); 

    else { 

     $topic = ForumTopic::where('slug', '=', $slug)->first(); 

     if (!is_null($topic)) 
      return Redirect::action('[email protected]', array('slug' => $slug)); 

     else 
      return 'fail'; 

    } 

}); 

和我有以下錯誤,當我試圖達成一個類別:

Route [[email protected]] not defined.

這是我的論壇類別控制器:

class ForumCategoryController extends BaseController { 

    public function findBySlug($slug) { 

     $category = ForumCategory::where('slug', '=', $slug)->first(); 

     return View::make('forum.category', array(
      'title'   => 'Catégorie', 
      'category'  => $category 
     )); 

    } 

} 

問題在哪裏?有沒有辦法做得更好?請幫助:)

回答

4

Laravel是告訴你要定義路由使用Route::action(),像:

Route::get('forum/bySlug/{slug}', '[email protected]'); 

因爲它實際上將構建一個URL和consumme它:

http://your-box/forum/bySlug/{slug} 

對於它必須找到指向你的行動路線。

+1

它沒有任何意義,因爲如果您以這種方式註冊路由,則不需要使用操作方法,您可以使用url :: to() – keren