lumen:App\Http \Controllers\Controller类未找到与全新安装 [英] lumen: App\Http\Controllers\Controller class not found with fresh install
问题描述
我正在使用全新安装 Lumen(构建网络API),大多数事情都可以正常工作,但是当我试图使用路由器指向一个类时,我得到这个错误:
致命错误:类'App\Http \Controllers\Controller'未在/ Applications / MAMP / htdocs / moments / lumen / app / Http / Controllers / MomentController.php on line 5
这是我的
<$ p> $ <$ c> $ app-> get('/' MomentController @ index');
这是我的类在app / Http / Controllers / MomentController。 php
<?php namespace App\Http \Controllers;
使用App\Http\Controllers\Controller;
class MomentController extends Controller {
public function index()
{
echo 123;
}
}
strong> bootstrap / app.php :
-
$ app-> withFacades / code>
-
$ app-> withEloquent();
-
Dotenv :: load(__ DIR __。'/ .. /');
这是我的 composer.json 文件:
{
name: laravel / lumen,
description:Laravel Lumen Framework。,
keywords:[framework,laravel,lumen],
license :MIT,
type:project,
require:{
laravel / lumen- framework:5.1。*,
vlucas / phpdotenv:〜1.0
},
require-dev:{
phpunit / phpunit:〜4.0,
fzaninotto / faker 〜1.0
},
autoload:{
psr-4:{
App\\:app /
},
classmap:[
database /
]
},
autoload-dev
tests /
]
},
config:{
preferred-install:dist
}
}
我认为它与命名空间有关,但我不能弄清楚。任何线索?
thx,
到右侧基本控制器,以便它可以扩展该类。
使用Laravel \Lumen\Routing\Controller作为BaseController;
这行是我必须添加才能使其工作。
所以完整的类变成这样:
<?php namespace App\ Http \Controllers;
使用Laravel \Lumen\Routing\Controller作为BaseController;
class ChannelController extends BaseController {
public function getChannels(){}
public function getChannel(){}
}
I'm working with a fresh install of Lumen (building a web API), most things work but when i'm trying to use the router to point to a class i get this error:
Fatal error: Class 'App\Http\Controllers\Controller' not found in /Applications/MAMP/htdocs/moments/lumen/app/Http/Controllers/MomentController.php on line 5
This is my router in app/Http/routes.php
$app->get('/', 'MomentController@index');
And this is my class in app/Http/Controllers/MomentController.php
<?php namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
class MomentController extends Controller {
public function index()
{
echo 123;
}
}
I have activated these components in bootstrap/app.php:
$app->withFacades();
$app->withEloquent();
Dotenv::load(__DIR__.'/../');
This is my composer.json file:
{
"name": "laravel/lumen",
"description": "The Laravel Lumen Framework.",
"keywords": ["framework", "laravel", "lumen"],
"license": "MIT",
"type": "project",
"require": {
"laravel/lumen-framework": "5.1.*",
"vlucas/phpdotenv": "~1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"fzaninotto/faker": "~1.0"
},
"autoload": {
"psr-4": {
"App\\": "app/"
},
"classmap": [
"database/"
]
},
"autoload-dev": {
"classmap": [
"tests/"
]
},
"config": {
"preferred-install": "dist"
}
}
I think it has something to do with the namespacing but i can't figure it out. Any clues?
thx,
The solution is to link to the right base controller so that it can extend of that class.
use Laravel\Lumen\Routing\Controller as BaseController;
This line is the only thing i had to add in order to make it work.
So the complete class becomes this:
<?php namespace App\Http\Controllers;
use Laravel\Lumen\Routing\Controller as BaseController;
class ChannelController extends BaseController {
public function getChannels(){}
public function getChannel(){}
}
这篇关于lumen:App\Http \Controllers\Controller类未找到与全新安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!