在 Laravel 4 中出现“找不到类 HTML”错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14192750/
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 07:28:11  来源:igfitidea点击:

Getting "Class HTML not found" error in Laravel 4

phplaravel

提问by Matanya

Working on a new project in Laravel 4 (a.k.a Illuminate) I'm trying to create the link to the style sheet in my master.blade.phptemplate like so:

在 Laravel 4(又名 Illuminate)中处理一个新项目,我试图在我的master.blade.php模板中创建指向样式表的链接,如下所示:

    {{ HTML::style('css\style.css') }}

But this throws an error saying the class HTML wasn't found. Has it been removed or renamed in Laravel 4, or am I forgetting anything else?

但这会引发错误,指出找不到 HTML 类。它是否在 Laravel 4 中被删除或重命名,或者我忘记了什么?

回答by daylerees

The generator type classes such as HTML:: and Form:: have been removed from L4 for best practice reasons. It would be better to render as tag using the path() method to link the attribute :

出于最佳实践的原因,诸如 HTML:: 和 Form:: 之类的生成器类型类已从 L4 中删除。使用 path() 方法将属性渲染为标签会更好:

<link href="{{ path('to/my/style.css') }}" />

They may be added in later for backwards compatibility, we will see. Please remember that L4 is currently in an alpha state.

稍后可能会添加它们以实现向后兼容性,我们将看到。请记住,L4 目前处于 alpha 状态。

Thanks! Dayle Rees.

谢谢!戴尔里斯。

回答by iicmaster

They just bring it back in Apr 02, 2013, But use Htmlinstead HTML

他们只是在 2013 年 4 月 2 日将其带回来,但Html改为使用HTML

eg. {{ Html::style('css\style.css') }}(now they change it again, this is not working anymore)

例如。{{ Html::style('css\style.css') }}(现在他们又改了,这不再起作用了)

Refer: Add missing HTML::script and HTML::style

参考:添加缺少的 HTML::script 和 HTML::style

Update : Its "HTML" again!!! (Thanks @milad-rey)

更新:又是“HTML”!!!(感谢@milad-rey)

for now please use this {{ HTML::style('css\style.css') }}

现在请使用这个 {{ HTML::style('css\style.css') }}

Refer: Updates for the rename of the HTMLfacade.

请参阅:更新HTML外观的重命名。

回答by EpokK

HTML and Form classes have been removed. You can install HTML port with composer here : https://github.com/meido/html

HTML 和 Form 类已被删除。您可以在此处使用 composer 安装 HTML 端口:https: //github.com/meido/html

or you can use this (on Laravel 4 Beta 5) :

或者你可以使用这个(在 Laravel 4 Beta 5 上):

<link rel="stylesheet" type="text/css" href="{{ URL::to('to/my/style.css') }}" />

<link rel="stylesheet" type="text/css" href="{{ URL::to('to/my/style.css') }}" />

回答by Megamind

use URL::asset('pathToAsset') ... i'm not quite sure, if this will be deprecated.

使用 URL::asset('pathToAsset') ...我不太确定,这是否会被弃用。

回答by William Cahill-Manley

In Laravel 4 both the HTML and Form classes have been removed due to existing third party packages that can now be found via composer. You can search for one you like, or meido has ported the existing HTMLand Formclasses over. See their pages for install instructions.

在 Laravel 4 中,由于现有的第三方包现在可以通过 composer 找到,HTML 和 Form 类都已被删除。您可以搜索您喜欢的一个,或者 meido 已经移植了现有的HTMLForm类。有关安装说明,请参阅他们的页面。

回答by scrfix

It has been removed. However there are a couple of things you can do Try out the: http://laravelbook.github.io/laravel4-powerpack/The powerpack states that it will bring it back.

它已被移除。但是,您可以做一些事情 试试看:http://laravelbook.github.io/laravel4-powerpack/powerpack 声明它将把它带回来。

OR use the HTML such as mentioned in another post:

或者使用另一篇文章中提到的 HTML:

<link rel="stylesheet" type="text/css" href="{{ URL::to('pathto/styleheet.css') }}" />

For hyperlinks to named routes just in case other people are looking for them as well:

对于命名路由的超链接,以防其他人也在寻找它们:

echo "<a href=\"" . URL::route('routeNameHere') . "\">Control Page</a>";
or $url = URL::route('routeNameHere');

see http://four.laravel.com/docs/routing

http://four.laravel.com/docs/routing

回答by quantme

<?php /* outputs string: http://yoursite.com/pathToAsset */ ?>
{{ URL::asset('/css/style.css') }}


<?php /* outputs html tag: `<a href="http://yoursite.com/home">Home</a>` */ ?>
{{ Html::link('home', 'Home') }}

Check /vendor/laravel/frameworj/src/Illuminate//Html/HtmlBuilder.phpmethods. Don't know where the *ell is /vendorfolder? You've been missing Composer.

检查/vendor/laravel/frameworj/src/Illuminate//Html/HtmlBuilder.php方法。不知道 *ell/vendor文件夹在哪里?你一直缺少Composer

composer.json

作曲家.json

The best part (no more 'illumination/foundation', 'til now):

最好的部分(不再是“照明/基础”,“直到现在”):

{
  ...
  "require": {
    ...
    "laravel/framework": "4.0.*"
  },
  ...
}

Proved 'til 2013-05-03 12:50

证明直到 2013-05-03 12:50