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

三世轮回 提交于 2019-12-22 09:02:15

问题


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');

I get the message:

No hint path defined for [subby]

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


回答1:


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

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

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


来源:https://stackoverflow.com/questions/22135765/laravel-using-packages-with-psr-4-gives-message-no-hint-path-defined-for

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!