Laravel 5.5-找不到类自定义BaseController但存在 [英] Laravel 5.5 - Class Custom BaseController not found but exists
问题描述
Laravel 5.5自定义BaseController
找不到,即使它存在.已经检查了StackOverflow
上与找不到的BaseController
有关的其他问题,但它们是指默认的BaseController
,在我的情况下是不相同的.
Laravel 5.5 Custom BaseController
not found even though it exists. Have checked the other questions on StackOverflow
regarding the BaseController
not found but they are referring to the default BaseController
which isn't the same in mine case.
这是我的实现方式
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as CheckController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
class Controller extends CheckController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
自定义BaseController(BaseController.php)
use App\Http\Controllers\Controller;
class BaseController extends Controller
{
/**
* Setup the layout used by the controller.
*
* @return void
*/
public $data = array();
public function __construct()
{
if (Sentinel::check()) {
// User is not logged in, or is not activated
$this->data['admin'] = Sentinel::getUser();
}
}
protected function setupLayout()
{
if (!is_null($this->layout)) {
$this->layout = View::make($this->layout);
}
}
}
将名为HomeCtontroller
的类扩展到自定义BaseController
Extending a class named HomeCtontroller
to Custom BaseController
class HomeController extends BaseController {
protected $layout = 'master';
public function main()
{
...
}
}
然后给出以下错误
Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN)
Class 'BaseController' not found
将感谢各种指针.
推荐答案
我相信您还没有包含完整的名称空间.
I believe you haven't included full namespaces.
确保在BaseController中具有:
Make sure in BaseController you have:
namespace App\Http\Controllers;
并在HomeController
中确保您正在使用:
and in HomeController
make sure you are using:
use App\Http\Controllers\BaseController;
所有这些控制器都应位于app/Http/Controllers
目录中.
all those controllers should be located in app/Http/Controllers
directory.
如果确定您具有有效的目录和名称空间,请在控制台中运行composer dump-autoload
If you are sure you have valid directories and namespaces run composer dump-autoload
in console
这篇关于Laravel 5.5-找不到类自定义BaseController但存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!