Laravel使用包含PSR-4的软件包给消息"没有为"定义提示路径。

时间:2014-03-03 00:41:11

标签: php laravel laravel-4 psr-4

我使用Laravel 4.1并启动使用PSR-4标准的软件包(subby)。 当我尝试使用以下内容渲染任何视图时:

return View::make('subby::user.login');

我收到消息:

No hint path defined for [subby]

我有很多东西,但那些通常是拼写错误

1 个答案:

答案 0 :(得分:14)

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

src
├── config
├── lang
├── migrations
├── Ghunti
│   └── Subby
│       └── SubbyServiceProvider.php
├── routes.php
└── views
    └── user
        └── login.blade.php

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

src
├── config
├── lang
├── migrations
├── SubbyServiceProvider.php
├── routes.php
└── views
    └── user
        └── login.blade.php

要解决此问题,请使用包服务提供商boot()方法,而不是:

public function boot()
{
    $this->package('ghunti/subby');
}

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

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