我第一次使用Lumen框架,路由/到我的HomeController不工作.
这是我的route.PHP:
$app->get('/','HomeController@index');
但是我收到以下错误:
[2015-04-17 07:03:41] lumen.ERROR: exception 'ReflectionException' with message 'Class HomeController does not exist' in /Users/refear99/Web/qingsongchou_api/vendor/illuminate/container/Container.PHP:776 Stack trace: #0 /Users/refear99/Web/qingsongchou_api/vendor/illuminate/container/Container.PHP(776): ReflectionClass->__construct('HomeController') #1 /Users/refear99/Web/qingsongchou_api/vendor/illuminate/container/Container.PHP(656): Illuminate\Container\Container->build('HomeController',Array) #2 /Users/refear99/Web/qingsongchou_api/vendor/laravel/lumen-framework/src/Application.PHP(358): Illuminate\Container\Container->make('HomeController',Array) #3 /Users/refear99/Web/qingsongchou_api/vendor/laravel/lumen-framework/src/Application.PHP(1184): Laravel\Lumen\Application->make('HomeController') #4 /Users/refear99/Web/qingsongchou_api/vendor/laravel/lumen-framework/src/Application.PHP(1157): Laravel\Lumen\Application->callControllerAction(Array) #5 /Users/refear99/Web/qingsongchou_api/vendor/laravel/lumen-framework/src/Application.PHP(1142): Laravel\Lumen\Application->callActionOnArrayBasedRoute(Array) #6 /Users/refear99/Web/qingsongchou_api/vendor/laravel/lumen-framework/src/Application.PHP(1120): Laravel\Lumen\Application->handleArrayBasedFoundRoute(Array) #7 /Users/refear99/Web/qingsongchou_api/vendor/laravel/lumen-framework/src/Application.PHP(1058): Laravel\Lumen\Application->handleFoundRoute(Array) #8 /Users/refear99/Web/qingsongchou_api/vendor/laravel/lumen-framework/src/Application.PHP(1006): Laravel\Lumen\Application->dispatch(NULL) #9 /Users/refear99/Web/qingsongchou_api/public/index.PHP(28): Laravel\Lumen\Application->run() #10 {main}
这是我的HomeController.PHP在/ app / Http / Controllers /
<?PHP namespace App\Http\Controllers; class HomeController extends Controller { public function index() { echo 123; } }
问题是什么?
你必须使用完全合格的类名:
$app->get('/','App\Http\Controllers\HomeController@index');
或者将一个组中的所有路线(实际上是在Laravel 5中的引擎盖下)
$app->group(['namespace' => 'App\Http\Controllers'],function($group){ $group->get('/','HomeController@index'); $group->get('foo','FooController@index'); });