Lumen - Class url 不存在
Lumen - Class url does not exist
我正在使用 Lumen 创建一个网站,虽然我的控制器、路由和视图配置良好,但当我尝试在控制器中使用重定向功能时出现错误。
这是错误代码:
ReflectionException in Container.php line 736: Class url does not exist
in Container.php line 736
at ReflectionClass->__construct('url') in Container.php line 736
at Container->build('url', array()) in Container.php line 631
at Container->make('url', array()) in Application.php line 203
at Application->make('url') in Redirector.php line 39
at Redirector->to('http://opentracker.local/token/archived', '302', array(), null) in helpers.php line 246
at redirect('http://opentracker.local/token/archived') in TokenController.php line 51
at TokenController->unarchive('clickid')
at call_user_func_array(array(object(TokenController), 'unarchive'), array('clickid')) in Container.php line 507
at Container->call(array(object(TokenController), 'unarchive'), array('attribute' => 'clickid')) in RoutesRequests.php line 567
at Application->callControllerCallable(array(object(TokenController), 'unarchive'), array('attribute' => 'clickid')) in RoutesRequests.php line 534
at Application->callLumenController(object(TokenController), 'unarchive', array('1', array('as' => 'token.unarchive', 'uses' => 'App\Http\Controllers\TokenController@unarchive'), array('attribute' => 'clickid'))) in RoutesRequests.php line 507
at Application->callControllerAction(array('1', array('as' => 'token.unarchive', 'uses' => 'App\Http\Controllers\TokenController@unarchive'), array('attribute' => 'clickid'))) in RoutesRequests.php line 475
at Application->callActionOnArrayBasedRoute(array('1', array('as' => 'token.unarchive', 'uses' => 'App\Http\Controllers\TokenController@unarchive'), array('attribute' => 'clickid'))) in RoutesRequests.php line 460
at Application->handleFoundRoute(array('1', array('as' => 'token.unarchive', 'uses' => 'App\Http\Controllers\TokenController@unarchive'), array('attribute' => 'clickid'))) in RoutesRequests.php line 434
at Application->handleDispatcherResponse(array('1', array('as' => 'token.unarchive', 'uses' => 'App\Http\Controllers\TokenController@unarchive'), array('attribute' => 'clickid'))) in RoutesRequests.php line 367
at Application->Laravel\Lumen\Concerns\{closure}() in RoutesRequests.php line 610
at Application->sendThroughPipeline(array(), object(Closure)) in RoutesRequests.php line 368
at Application->dispatch(null) in RoutesRequests.php line 313
at Application->run() in index.php line 28
我的路线很好识别,(您可以在错误中看到它按应有的方式转换)。
这是我在控制器中使用的代码:
public function unarchive($attribute){
Token::query()->find($attribute)->update(['is_archived'=>0]);
return redirect(route('token.archived'));
}
我还取消了 boostrap/app.php 中的以下注释:
$app->withFacades();
$app->withEloquent();
在 Lumen 中使用函数 redirect()
有问题吗?我试了 redirect(route())
和 redirect()->route()
,他们给出了相同的结果。
如果您使用的是 5.2,则存在一个未解决的问题。
Lumen - Github Issues - redirect() doesn't work, Lumen 5.2 #315
如果需要可以直接使用Illuminate\Http\RedirectResponse
。 (来自下面的解决方法link):
return new RedirectResponse('login');
return RedirectResponse::create('login');
我正在使用 Lumen 创建一个网站,虽然我的控制器、路由和视图配置良好,但当我尝试在控制器中使用重定向功能时出现错误。
这是错误代码:
ReflectionException in Container.php line 736: Class url does not exist
in Container.php line 736
at ReflectionClass->__construct('url') in Container.php line 736
at Container->build('url', array()) in Container.php line 631
at Container->make('url', array()) in Application.php line 203
at Application->make('url') in Redirector.php line 39
at Redirector->to('http://opentracker.local/token/archived', '302', array(), null) in helpers.php line 246
at redirect('http://opentracker.local/token/archived') in TokenController.php line 51
at TokenController->unarchive('clickid')
at call_user_func_array(array(object(TokenController), 'unarchive'), array('clickid')) in Container.php line 507
at Container->call(array(object(TokenController), 'unarchive'), array('attribute' => 'clickid')) in RoutesRequests.php line 567
at Application->callControllerCallable(array(object(TokenController), 'unarchive'), array('attribute' => 'clickid')) in RoutesRequests.php line 534
at Application->callLumenController(object(TokenController), 'unarchive', array('1', array('as' => 'token.unarchive', 'uses' => 'App\Http\Controllers\TokenController@unarchive'), array('attribute' => 'clickid'))) in RoutesRequests.php line 507
at Application->callControllerAction(array('1', array('as' => 'token.unarchive', 'uses' => 'App\Http\Controllers\TokenController@unarchive'), array('attribute' => 'clickid'))) in RoutesRequests.php line 475
at Application->callActionOnArrayBasedRoute(array('1', array('as' => 'token.unarchive', 'uses' => 'App\Http\Controllers\TokenController@unarchive'), array('attribute' => 'clickid'))) in RoutesRequests.php line 460
at Application->handleFoundRoute(array('1', array('as' => 'token.unarchive', 'uses' => 'App\Http\Controllers\TokenController@unarchive'), array('attribute' => 'clickid'))) in RoutesRequests.php line 434
at Application->handleDispatcherResponse(array('1', array('as' => 'token.unarchive', 'uses' => 'App\Http\Controllers\TokenController@unarchive'), array('attribute' => 'clickid'))) in RoutesRequests.php line 367
at Application->Laravel\Lumen\Concerns\{closure}() in RoutesRequests.php line 610
at Application->sendThroughPipeline(array(), object(Closure)) in RoutesRequests.php line 368
at Application->dispatch(null) in RoutesRequests.php line 313
at Application->run() in index.php line 28
我的路线很好识别,(您可以在错误中看到它按应有的方式转换)。
这是我在控制器中使用的代码:
public function unarchive($attribute){
Token::query()->find($attribute)->update(['is_archived'=>0]);
return redirect(route('token.archived'));
}
我还取消了 boostrap/app.php 中的以下注释:
$app->withFacades();
$app->withEloquent();
在 Lumen 中使用函数 redirect()
有问题吗?我试了 redirect(route())
和 redirect()->route()
,他们给出了相同的结果。
如果您使用的是 5.2,则存在一个未解决的问题。
Lumen - Github Issues - redirect() doesn't work, Lumen 5.2 #315
如果需要可以直接使用Illuminate\Http\RedirectResponse
。 (来自下面的解决方法link):
return new RedirectResponse('login');
return RedirectResponse::create('login');