Laravel 5.1:类 html 不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31350030/
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.1: Class html does not exist
提问by Michiel van der Blonk
I am upgrading from 4.2 directly to 5.1 and run into problems with the Html and Form classes.
我正在从 4.2 直接升级到 5.1,但遇到了 Html 和 Form 类的问题。
I followed the upgrade notes, and did
我遵循了升级说明,并做到了
- add "laravelcollective/html": "~5.0" to composer.json
- composer update
- add Collective\Html\HtmlServiceProvider::class to providers in app.php
- add Form' => Collective\Html\FormFacade::class, Html' => Collective\Html\HtmlFacade::class to aliases in app.php
- 将 "laravelcollective/html": "~5.0" 添加到 composer.json
- 作曲家更新
- 将 Collective\Html\HtmlServiceProvider::class 添加到 app.php 中的提供者
- 添加 Form' => Collective\Html\FormFacade::class, Html' => Collective\Html\HtmlFacade::class 到 app.php 中的别名
But my views don't work. I get either Class HTML does not exist
when using HTML::router or get Class html does not exist
when using link_to_route
但我的观点行不通。我要么Class HTML does not exist
在使用 HTML::router 时得到,要么Class html does not exist
在使用 link_to_route 时得到
I also tried Illuminate\html
instead of laravelcollective
, I did a composer dump-autoload
.
我也尝试过,Illuminate\html
而不是laravelcollective
,我做了一个composer dump-autoload
.
The complete errors:
完整的错误:
ErrorException in Container.php line 736: Class html does not exist (View: C:\Dev\www\admin\resources\views\clubs\index.blade.php)
ReflectionException in Container.php line 736: Class html does not exist
What am I missing?
我错过了什么?
I tried everyone's answers and none of them worked for me for some reason. Ultimately I created a completely new laravel application, copied my code and then it started working, So though solved the actual problem remains a mystery.
我尝试了每个人的答案,但出于某种原因,没有一个对我有用。最终我创建了一个全新的 Laravel 应用程序,复制了我的代码然后它开始工作,所以虽然解决了实际问题仍然是一个谜。
采纳答案by Michiel van der Blonk
My problem is solved, but the actual cause is still unknown. I have created a completely new laravel install and copied my source (all of it). The new application worked right away (after installing illuminate/html).
我的问题已解决,但实际原因仍然未知。我已经创建了一个全新的 laravel 安装并复制了我的源代码(全部)。新应用程序立即运行(在安装illuminate/html 之后)。
So you think I did something wrong with packages? That's what I thought, and then I did a diff on the two directories, only to find out they were identical. So it's a real mystery.
所以你认为我在包裹上做错了什么?我就是这么想的,然后我对这两个目录进行了比较,结果发现它们是相同的。所以这是一个真正的谜。
So, now everything is working, I simply renamed my new application and can continue.
因此,现在一切正常,我只需重命名我的新应用程序即可继续。
I do know at some point I probably had both the collective and the illuminate versions of the HTML package installed. That's what most likely corrupted everything.
我确实知道在某些时候我可能同时安装了 HTML 包的集体版本和说明版本。这就是最有可能破坏一切的原因。
回答by animesh manglik
Add in composer.json
在 composer.json 中添加
"illuminate/html": "5.*"
and run composer update
并运行作曲家更新
Open your config/app.php
打开你的 config/app.php
add under 'providers'
在“提供者”下添加
Illuminate\Html\HtmlServiceProvider::class,
add under 'aliases'
在“别名”下添加
'Form' => Illuminate\Html\FormFacade::class,
'Html' => Illuminate\Html\HtmlFacade::class,
and under your blade templates, use as such
并在您的刀片模板下,按原样使用
{!! HTML::style('assets/css/flatten.css') !!}
回答by Yurii Svystun
My solution in my case it was problem with CASE-Sensitive class name.
我的解决方案是 CASE-Sensitive 类名有问题。
In my config/app.php (in aliases)
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
I am tried to use in view this code:
我试图在查看此代码时使用:
{!! HTML::mailto('mailto:[email protected]', '[email protected]'); !!}
and that was an error:
这是一个错误:
"FatalErrorException in ccf70b1d0b9930d6c4e8f3859fff448f line 11: Class 'HTML' not found"
Name of class 'HTML' is CASE-Sensitive. You should use 'Html' as in your config (config/app.php) file.
“HTML”类的名称区分大小写。您应该在配置 (config/app.php) 文件中使用“Html”。
Hope this help for some people.
希望这对某些人有所帮助。
回答by shijinmon Pallikal
Please change your blade file from this
请从此更改您的刀片文件
{{ HTML::style('css/bootstrap.min.css') }}
to
到
{{ Html::style('css/bootstrap.min.css') }}
It's working.
它正在工作。
回答by manshu
A simple restart after composer update worked perfectly for me. I was looking for the answer, and got stuck at the same position. I'd suggest, run config:cache and cache:clear and restart the IDE. It will work.
作曲家更新后的简单重启对我来说非常有效。我一直在寻找答案,却卡在了同一个位置。我建议,运行 config:cache 和 cache:clear 并重新启动 IDE。它会起作用。
回答by madSkillz
I think I have found the solution.
我想我已经找到了解决办法。
In your app.php
you have declared
在app.php
你已经声明
'Form' => Illuminate\Html\FormFacade::class,
'Html' => Illuminate\Html\HtmlFacade::class,
While in your View
you have called the same class as
在你的时候,View
你已经调用了相同的类
{!! HTML::style('css/bootstrap.min.css') !!}
There is nothing wrong with the packages as the marked answer above but rather difference in capitalization of the word HTML
as the previous documentation ver 5.0.*.
作为上述标记答案的包没有任何问题,但HTML
与之前的文档版本 5.0.* 相比,单词的大小写有所不同。
It should be
它应该是
'Form' => Illuminate\Html\FormFacade::class,
'HTML' => Illuminate\Html\HtmlFacade::class,
回答by Sergey
Try it
尝试一下
php artisan cache:clear
php artisan clear-compiled
php artisan 缓存:清除
php artisan 清晰编译
回答by EricZ
edit config/app.php
编辑config/app.php
add this into providers
将此添加到提供程序中
Collective\Html\HtmlServiceProvider::class,
and this into aliases
并将其转换为别名
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
回答by channasmcs
this is right way If you try to use Form::open() or any of the Form methods in a fresh Laravel 5 install, you would get something like this: http://laraveldaily.com/class-form-not-found-in-laravel-5/
这是正确的方法如果您尝试在新的 Laravel 5 安装中使用 Form::open() 或任何 Form 方法,您会得到如下内容:http://laraveldaily.com/class-form-not-found -in-laravel-5/