在Laravel 4的app/config/app.php
中,我在providers
下找到以下行:
'Illuminate\Workbench\WorkbenchServiceProvider',
该服务提供商的工作原理是因为我验证了register()
方法被调用。我想知道这是如何映射出名称空间的。至少部分地看来,Illuminate
:
/vendor/composer/autoload_namespaces.php
'Illuminate' => array($vendorDir . '/laravel/framework/src'),
我在/vendor
中创建了一个名为
/vendor/mycompany
然后创建一个名为MyClass.php的类文件,如下所示
<?php namespace MyCompany;
#MyClass.php
class MyClass{
..etc..
}
然后我在/vendor/composer/autoload_namespaces.php
中添加相同的行:
'MyCompany' => array($vendorDir . '/mycompany'),
并在routes.php中调用以下内容:
$test = new MyCompany\MyClass; //line 15
print_r(class_get_methods($test)); //line 16
但是,我收到了这个错误:
Fatal error: Class 'MyCompany\MyClass' not found in .. line 15
如何解决这个问题并获得注册和识别的命名空间MyCompany
?