Laravel,将包与PSR-4一起使用,会给出消息“未定义提示路径". [英] Laravel, using packages with PSR-4 gives message "No hint path defined for"

查看:156
本文介绍了Laravel,将包与PSR-4一起使用,会给出消息“未定义提示路径".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

我收到消息:

No hint path defined for [subby]

我已经做了很多事情,但是这些通常都是错字问题

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

推荐答案

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

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:

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

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

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:

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

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

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

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__);
}

这篇关于Laravel,将包与PSR-4一起使用,会给出消息“未定义提示路径".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆