Laravel,使用PSR-4包提供消息"没有定义提示路径"

Gon*_*rós 4 php laravel laravel-4 psr-4

我正在使用Laravel 4.1并启动使用PSR-4标准的软件包(subby).当我尝试渲染任何视图时:

return View::make('subby::user.login');
Run Code Online (Sandbox Code Playgroud)

我收到消息:

No hint path defined for [subby]
Run Code Online (Sandbox Code Playgroud)

我有很多东西,但那些通常是错字问题

Gon*_*rós 14

问题在于PSR-4的使用,因为Laravel默认为PSR-0,它假定包的资源(视图等)将比包服务提供者的位置高2级.例如:

src
??? config
??? lang
??? migrations
??? Ghunti
?   ??? Subby
?       ??? SubbyServiceProvider.php
??? routes.php
??? views
    ??? user
        ??? login.blade.php
Run Code Online (Sandbox Code Playgroud)

使用PSR-4,包服务提供者和视图将处于同一级别(并且将显示错误"未定义提示路径":

src
??? config
??? lang
??? migrations
??? SubbyServiceProvider.php
??? routes.php
??? views
    ??? user
        ??? login.blade.php
Run Code Online (Sandbox Code Playgroud)

要解决此问题,请在包服务提供者boot()方法上执行此操作,而不是:

public function boot()
{
    $this->package('ghunti/subby');
}
Run Code Online (Sandbox Code Playgroud)

我们需要指定资源路径(第3个参数)

public function boot()
{
    //For PSR-4 compatibility we need to specify the correct path (3rd parameter)
    $this->package('ghunti/subby', null, __DIR__);
}
Run Code Online (Sandbox Code Playgroud)