Laravel 4 Redirect :: action()“未定义路由" [英] Laravel 4 Redirect::action() "Route not defined"
问题描述
我目前在Laravel 4上遇到麻烦.我想将Slug用于论坛类别和论坛主题(slug是唯一的).为了确定用户是属于类别还是主题,我采用以下路线:
I'm currently having troubles with Laravel 4. I would like to use slugs for forum categories and forum topics (slugs are unique). In order to determinate if the user is in a category or in a topic, I have this route:
Route::get('forum/{slug}', function($slug) {
$category = ForumCategory::where('slug', '=', $slug)->first();
if (!is_null($category))
return Redirect::action('ForumCategoryController@findBySlug', array('slug' => $slug));
else {
$topic = ForumTopic::where('slug', '=', $slug)->first();
if (!is_null($topic))
return Redirect::action('ForumTopicController@findBySlug', array('slug' => $slug));
else
return 'fail';
}
});
当我尝试进入类别时出现以下错误:
And I have the following error when I try to reach a category:
Route [ForumCategoryController@findBySlug] not defined.
这是我的ForumCategoryController:
Here is my ForumCategoryController:
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
));
}
}
问题出在哪里?有什么办法可以做得更好?请帮助:)
Where is the problem ? Is there a way to do it better ? Help please :)
推荐答案
Laravel告诉您必须定义一条使用Route::action()
的路由,例如:
Laravel is telling that you have to define a route to use Route::action()
, something like:
Route::get('forum/bySlug/{slug}', 'ForumTopicController@findBySlug');
因为它实际上将构建一个URL并使用它:
Because it will actually build an url and consumme it:
http://your-box/forum/bySlug/{slug}
为此,它必须找到指向您的操作的路线.
For that it must find a route pointing to your action.
这篇关于Laravel 4 Redirect :: action()“未定义路由"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!