Laravel-刀片注释,刀片渲染导致页面崩溃 [英] Laravel - Blade comments , blade rendering causing page to crash

查看:119
本文介绍了Laravel-刀片注释,刀片渲染导致页面崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Laravel中渲染一个页面,该页面主要是带有view::make的表单,并且该页面崩溃了,从而导致ERR_CONNECTION_RESET.经过长时间的调查和许多红色的鲱鱼,我开始从刀片文件中擦除(不添加注释)该视图的随机部分,并意识到如果我

I'm rendering a page that is primarily a form with view::make in Laravel and it is crashing, causing ERR_CONNECTION_RESET. After a long investigation and many red herrings, I started erasing (not commenting) random sections out of the blade file for the view and realized that if I

a)清除表单此部分内{{Form}}调用中的2

a) erase 2 of the {{Form}} calls inside this section of the form

b)从表单的此部分附近删除{{-- and --}}

b) remove the {{-- and --}} from around this section of the form

    {{--
    <div class="form-row">
      {{ Form::label('foo', 'foo:') }}
      {{ Form::text('foo') }}
    </div>
    <div class="form-row">
      {{ Form::label('foo', 'foo:') }}
      {{ Form::text('foo') }}
    </div>
    <div class="form-row">
      {{ Form::label('foo', 'foo') }}
      {{ Form::text('foo') }}
    </div>
    --}}

页面将呈现.我不确定这里到底是什么原因.上面和下面还有其他块,尽管这是一个3格注释掉的部分,其他都不是.

the page will render. I am not sure what exactly the cause here is. There are other blocks above and below, although this is a 3-div commented out section which none of the others are.

有人知道这是什么原因吗?如果重要的话,可以在WAMP上运行.

Anyone have a clue what is causing this? Running on WAMP if that matters.

推荐答案

注意:此答案适用于Laravel 4.2,但仍应适用.某些Blade编译问题的特殊情况取决于Laravel和/或PHP的版本,因此最好仅在最简单的用例中使用Blade注释.

解决方案是仅对简单注释使用Blade注释,或注释掉单行Blade功能.不要将Blade/PHP代码嵌套在Blade注释中.使用标准的PHP块注释将单个注释(PHP,HTML,多个刀片功能等)中的多行代码注释掉.

有效刀片评论:

单刀片功能:

{{-- Form::text('foo') --}}

备注:

{{-- Form Section 1 --}}


无效的刀片评论:

语法错误:

{{-- Form::text('foo') --  }} 

"@"刀片内的评论

{{-- @Form::text('foo') --}} 

嵌套的PHP:

{{-- <?php 
echo "foo";
echo "bar
?> --}} 

嵌套刀片:

{{-- 
{{ HTML::form("foo") }};
{{ HTML::form("bar") }};
--}} 


改为使用PHP块注释.它们仍然可以在blade.php文件中使用

<?php /* 
{{ HTML::form("foo") }};
{{ HTML::form("bar") }};
*/ ?> 


或者,一次注释掉刀片中的一行:

{{-- HTML::form("foo") --}};
{{-- HTML::form("bar") --}};


内部:

对于OP的代码,Laravel的Blade Compiler将生成一个包含以下PHP/HTML的临时PHP文件:

For the OP's code, Laravel's Blade Compiler will generate a temporary PHP file containing the following PHP/HTML:

<?php /* 
    <div class="form-row">
      <?php echo Form::label('foo', 'foo:'); ?>

<?php echo Form::text('foo'); ?>

</div>
<div class="form-row">
    <?php echo Form::label('foo', 'foo:'); ?>

    <?php echo Form::text('foo'); ?>

</div>
<div class="form-row">
    <?php echo Form::label('foo', 'foo'); ?>

    <?php echo Form::text('foo'); ?>

</div>
*/ ?>

Blade注释中的Blade仍在解析为PHP. PHP注释中的PHP结束标记导致Apache的解析器提前结束,从而导致某些格式不正确的PHP/HTML可能使您的连接崩溃(可能是由于悬空的*/ ?>引起的).

The Blade inside of your Blade comments are still being parsed into PHP. The PHP end tags inside of the PHP block-comment is causing the Apache's parser to end early, resulting in some badly-formed PHP/HTML that could be crashing your connection (likely caused by the dangling */ ?>).

?>退出PHP模式并返回HTML模式,并且//或# 不能影响那.

?> breaks out of PHP mode and returns to HTML mode, and // or # cannot influence that.

使用任何上述无效的Blade注释都会导致类似的编译问题.避免对Blade进行注释或注释,而不必一次注释一行.

Using any of the aforementioned invalid Blade comments will cause similar compilation issues. Avoid Blade comments for anything other than remarks or commenting Blade functions out one line at a time.

这篇关于Laravel-刀片注释,刀片渲染导致页面崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆