我正在尝试在 Laravel 4.1 中创建一个模块化系统。
我有以下文件夹:
app
app/controllers
app/controllers/BaseController.php
app/views/
app/modules/
app/modules/moduleName/
app/modules/moduleName/routes.php
app/modules/moduleName/controllers/
app/modules/moduleName/controllers/module.php
当我尝试扩展BaseController
时,我使用命名空间,我收到以下错误:
Symfony \ Component \ Debug \ Exception \ FatalErrorException
Class 'Illuminate\Session' not found
这是我的module.php代码:
<?php namespace App\Modules\Twitter\Controllers;
use Illuminate\Routing\Controllers\Controller;
class Modulename extends Controller {
}
我有两个问题。
非常感谢。
答案 0 :(得分:1)
Laravel库都存在于全局命名空间中,因此如果您使用任何类型的命名空间代码,则需要指定要调用的库。
使用您提供的代码,就像这样:
<?php namespace App\Modules\Twitter\Controllers;
use Controller, Session;
class Modulename extends Controller {
}
这样可以节省您输入整个命名空间的费用。