Laravel路线有2个参数

时间:2014-06-13 16:00:53

标签: php laravel

我有路线结构:

Route::group(array('before' => 'auth'), function() {
    Route::controller('/app/{companyId}', 'AppController');
    Route::controller('/app/{companyId}/projects/{projectId}', 'ProjectsController');
    Route::controller('/app/{companyId}/task/{taskId}', 'TasksController');
    Route::controller('/app/{companyId}/bugs/{bugId}', 'BugsController');
    Route::controller('/app/{companyId}/comments/{commentId}', 'CommentsController');
    Route::controller('/app/{companyId}/calendar', 'CalendarController');
    Route::controller('/', 'CompaniesController');
});

但是当我试图打开/ app / 3 / project / 1时,它无法正常工作:

Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException
Controller method not found.

什么可能导致这个问题?

正确的解决方案:检查路线的正确顺序(最长的mut位于顶部):

Route::controller('app/{companyId}/project/{projectId}', 'ProjectsController');
Route::controller('app/{companyId}/task/{taskId}', 'TasksController');
Route::controller('/app/{companyId}/bugs/{bugId}', 'BugsController');
Route::controller('/app/{companyId}/comments/{commentId}', 'CommentsController');
Route::controller('/app/{companyId}/calendar', 'CalendarController');
Route::controller('/app/{companyId}', 'AppController');
Route::controller('/', 'CompaniesController');

2 个答案:

答案 0 :(得分:1)

一点点实验,我发现了bug。原因在于路线的位置。这很有效。

Route::controller('app/{companyId}/project/{projectId}', 'ProjectsController');
Route::controller('app/{companyId}/task/{taskId}', 'TasksController');
Route::controller('/app/{companyId}/bugs/{bugId}', 'BugsController');
Route::controller('/app/{companyId}/comments/{commentId}', 'CommentsController');
Route::controller('/app/{companyId}/calendar', 'CalendarController');
Route::controller('/app/{companyId}', 'AppController');
Route::controller('/', 'CompaniesController');

由于

答案 1 :(得分:0)

试试这个:

首先你必须指定路由方法(get或post),然后你必须加入@,动作名称将在指定的控制器中执行

Route::get('/app/{companyId}/bugs/{bugId}', 'BugsController@actionname');