Laravel,使用带有 PSR-4 的包会给出消息“未定义提示路径”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22135765/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 09:07:48  来源:igfitidea点击:

Laravel, using packages with PSR-4 gives message "No hint path defined for"

phplaravellaravel-4psr-4

提问by Gon?alo Queirós

Im using Laravel 4.1 and starting a package (subby) that is using PSR-4 standard. When I try to render any view with:

我使用 Laravel 4.1 并启动一个使用 PSR-4 标准的包(subby)。当我尝试渲染任何视图时:

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

I get the message:

我收到消息:

No hint path defined for [subby]

I've red many things, but those were usually typo problems

我已经红色了很多东西,但那些通常是错字问题

回答by Gon?alo Queirós

The problem is in the usage of the PSR-4 Since Laravel default is PSR-0 it assumes that the resources (views etc) of a package will be 2 levels up from where the package service provider is. Ex:

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

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

With PSR-4 the package service provider and the views will be at the same level (and the error "No hint path defined for" will show up:

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

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

To fix this, on the package service provider boot()method, instead of:

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

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

we need to specify the resources path (the 3rd parameter)

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

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