8

只是在玩 Laravel 5,并且在使用 Blade 模板语法时遇到了困难。看来我所有的特殊字符都被转义了。我的设置有问题吗?

只是为了显示我的设置,我已将以下内容添加到config/app.php

别名:'Form' => 'Illuminate\Html\FormFacade', 'Html' => 'Illuminate\Html\HtmlFacade' 服务提供商:'Illuminate\Html\HtmlServiceProvider'

现在这是我的刀片视图:

@extends('layout')

@section('content')

    {{ Form::open() }}

    {{ Form::close() }}

@stop

这是浏览器中的输出:

<form method="POST" action="http://test.app:8000/categories/create" accept-charset="UTF-8"><input name="_token" type="hidden" value="m4RdpqdbbqQ2F7iwfDkSDKTzEmaBGNvpJbj5LnqE"> </form>

这是视图源的输出:

<!doctype HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>My Site</title>
    </head>
    <body>

        <header></header>

        <content>
    &lt;form method=&quot;POST&quot; action=&quot;http://test.app:8000/categories/create&quot; accept-charset=&quot;UTF-8&quot;&gt;&lt;input name=&quot;_token&quot; type=&quot;hidden&quot; value=&quot;m4RdpqdbbqQ2F7iwfDkSDKTzEmaBGNvpJbj5LnqE&quot;&gt;

    &lt;/form&gt;

</content>

    </body>
</html>
4

2 回答 2

31

Laravel 5中,{{ }}会自动转义。您现在需要使用的是{!! !!}.

{!! Form::open() !!}

{!! Form::close() !!}

有关更改的更多信息,请参见https://laracasts.com/discuss/channels/general-discussion/new-blade-tag-for-unescaped-data-thoughts(感谢 @user1960364)。

于 2014-09-14T11:33:22.513 回答
1

如果您必须使用旧的(L4.2 或更低版本)Blade 语法,请在 AppServiceProvider@register 的底部添加以下行:

\Blade::setRawTags('{{', '}}');
\Blade::setContentTags('{{{', '}}}');
\Blade::setEscapedContentTags('{{{', '}}}');

这不应该轻易完成,并且可能会使您的应用程序更容易受到 XSS 攻击,因此请谨慎使用。

于 2015-02-17T18:17:31.160 回答