Laravel 5 和 Illuminate/html
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31520667/
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
Laravel 5 and Illuminate/html
提问by senty
I am trying to use {{ HTML }}
in my project however I am running into several errors. I researched on internet about the problem, and I believe I am doing the right steps, however, I keep falling in the same error while I am trying to load my master page.
我正在尝试{{ HTML }}
在我的项目中使用,但是我遇到了几个错误。我在互联网上研究了这个问题,我相信我正在做正确的步骤,但是,当我尝试加载我的母版页时,我一直陷入同样的错误。
FatalErrorException in ... line 9: Class 'HTML' not found
FatalErrorException in ... line 9: Class 'HTML' not found
So what I did was:
所以我所做的是:
Edited the
composer.json
file and added"illuminate/html": "5.*"
underrequire {}
Run
composer update
(everything seems fine)Added:
providers => 'Illuminate\Html\HtmlServiceProvider',
as well as`aliasses => 'Form' => 'Illuminate\Html\FormFacade', 'Html' => 'Illuminate\Html\HtmlFacade',
编辑
composer.json
文件并添加"illuminate/html": "5.*"
到require {}
运行
composer update
(一切似乎都很好)补充:
providers => 'Illuminate\Html\HtmlServiceProvider',
还有`aliasses => 'Form' => 'Illuminate\Html\FormFacade', 'Html' => 'Illuminate\Html\HtmlFacade',
(Even though the ones already placed under aliasses and providers are as follows which seems the ones I added looks quite different than the rest:
(即使已经放置在别名和提供者下的如下所示,我添加的看起来与其他看起来完全不同:
Illuminate\Validation\ValidationServiceProvider::class,
Illuminate\View\ViewServiceProvider::class,
'Illuminate\Html\HtmlServiceProvider', // The one I added
'URL' => Illuminate\Support\Facades\URL::class,
'Validator' => Illuminate\Support\Facades\Validator::class,
'View' => Illuminate\Support\Facades\View::class,
'Form' => 'Illuminate\Html\FormFacade', // I added
'Html' => 'Illuminate\Html\HtmlFacade', // I added
And here is the snippet version of my master.blade.php
:
这是我的片段版本master.blade.php
:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset = "UTF-8">
<title></title>
{{ HTML::script('js/jquery.js') }} // Line 9
{{ HTML::script('js/bootstrap.js') }} // Line 10
{{ HTML::style('css/bootstrap.js') }} // Line 11
</head>
The error I am getting is:
我得到的错误是:
FatalErrorException in ### line 9: Class 'HTML' not found in
/Applications/MAMP/htdocs/laratest/storage/framework/views/### line 9
FatalErrorException in ### line 9: Class 'HTML' not found in
/Applications/MAMP/htdocs/laratest/storage/framework/views/### 第 9 行
I was benefiting from several tutorials such as This one on YouTubeand Laracast. I also found a Solved-tagged questionwhich is addressing the same issue but did not fix the issue in my case.
我从几个教程中受益,例如YouTube和Laracast上的 This one。我还发现了一个Solved-tagged question,它解决了同样的问题,但没有解决我的问题。
Edit: Also changing to {!! HTML !!}
is not working either
编辑:也更改为{!! HTML !!}
也不起作用
回答by Kyizin
Illuminate/HTML package has been deprecated
Illuminate/HTML 包已被弃用
Use:laravelcollective/html
使用:laravelcollective/html
composer require laravelcollective/html
Add this lines in config/app.php
在 config/app.php 中添加这一行
in providers group:
在提供者组中:
Collective\Html\HtmlServiceProvider::class,
in aliases group:
在别名组中:
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
回答by David Barker
First the facades aren't correct.
首先,外墙不正确。
'Form' => 'Illuminate\Html\FormFacade', // FormFacade not HtmlFacade
'Html' => 'Illuminate\Html\HtmlFacade',
The facade is Html
not HTML
.
门面Html
不是HTML
。
<!-- This won't work -->
{!! HTML::script('js/jquery.js') !!}
<!-- This should work -->
{!! Html::script('js/jquery.js') !!}
Or you could change the facade key to HTML
and then you can use HTML::script(...)
.
或者您可以将外观键更改为HTML
,然后您可以使用HTML::script(...)
.
'HTML' => 'Illuminate\Html\HtmlFacade'
回答by BrynJ
In migrating to 5.1 I found the same issue - it appears as though the HTML class no longer supports the script and style methods.
在迁移到 5.1 时,我发现了同样的问题 - 似乎 HTML 类不再支持脚本和样式方法。
Instead, use:
相反,使用:
{{ URL::asset('yourassetpath') }}
回答by Gaurav Dave
Try this:
尝试这个:
{!! HTML !!}
and, don't forgot to composer dumpautoload
.
并且,不要忘记composer dumpautoload
。
See, if that helps.
看看,如果这有帮助。
回答by elibyy
you are using two different aliases to the same facade. the correct facades are
您对同一个外观使用了两个不同的别名。正确的外墙是
'Form' => Illuminate\Support\Facades\Facade\FormFacade::class,
'Html' => Illuminate\Support\Facades\Facade\HtmlFacade::class,
this should work
这应该有效
p.s. as of laravel 5.1 you should use facadeName::class
ps 从 laravel 5.1 开始,你应该使用 facadeName::class