douyinliu8813
2018-08-13 08:18
采纳率: 100%
浏览 66
已采纳

为什么在symfony 3.4中呈现php模板是打印http标头?

I'm trying to move from a messy PHP template structure, with many duplicated code, to slots to help us having a similar twig philosophy with the extends.

The problem that we have is that some templates are rendering the HTTP Headers: enter image description here

The code for Form/form.html.php is:

<?php
/**
 * @var \Symfony\Bundle\FrameworkBundle\Templating\TimedPhpEngine    $view
 * @var \Symfony\Bundle\FrameworkBundle\Templating\Helper\FormHelper $formHelper
 * @var \Symfony\Component\Templating\Helper\SlotsHelper             $slotsHelper
 * @var \Symfony\Component\Form\FormView                             $form
 */
$formHelper = $view['form'];
$slotsHelper = $view['slots'];

?>
<div class="form-wrapper">
    <?php $slotsHelper->output('form-start', $formHelper->start($form)) ?>
    <?php $slotsHelper->output('form-widget', $formHelper->widget($form)) ?>
    <?php $slotsHelper->output('form-end', $formHelper->end($form)) ?>
</div>

And the code for the other template, Form/Order/form.html.php, is

<?php
/**
 * @var \Symfony\Bundle\FrameworkBundle\Templating\TimedPhpEngine    $view
 * @var \Symfony\Bundle\FrameworkBundle\Templating\Helper\FormHelper $formHelper
 * @var \Symfony\Component\Templating\Helper\SlotsHelper             $slotsHelper
 * @var \Symfony\Component\Form\FormView                             $form
 */
$formHelper = $view['form'];
$slotsHelper = $view['slots'];
$view->extend(':Form:form.html.php');

$slotsHelper->start('form-widget');
echo $formHelper->widget($form);
$slotsHelper->stop();

In the Controller, I'm rendering the form as always I've rendered a form:

$this->render("Form/Order/form.html.php", ['form' => $orderForm->createView()])

If I change this sentence by "returned string", Symfony prints only this "returned string", not the headers.

The form is rendered correctly, but for some reason that I cannot understand, Symfony is printing the HTTP Headers.

Thanks!

图片转代码服务由CSDN问答提供 功能建议

我正试图从一个混乱的PHP模板结构(带有许多重复的代码)转移到插槽,以帮助我们在扩展中使用类似的twig哲学。

我们遇到的问题是某些模板正在呈现HTTP标头:

Form / form.html.php的代码是:

 &lt;?php 
 / ** 
 * @var \ Symfony \ Bundle \ FrameworkBundle \ Templating \  TimedPhpEngine $ view 
 * @var \ Symfony \ Bundle \ FrameworkBundle \ Templating \ Helper \ FormHelper $ formHelper 
 * @var \ Symfony \ Component \ Templating \ Helper \ SlotsHelper $ slotsHelper 
 * @var \ Symfony \ Component \ Form  \ FormView $ form 
 * / 
 $ formHelper = $ view ['form']; 
 $ slotsHelper = $ view ['slots']; 
 
?&gt; 
&lt; div class =“form- 包装“&gt; 
&lt;?php $ slotsHelper-&gt;输出('form-start',$ formHelper-&gt; start($ form))?&gt; 
&lt;?php $ slotsHelper-&gt; output(  'form-widget',$ formHelper-&gt; widget($ form))?&gt; 
&lt;?php $ slotsHelper-&gt; output('form-end',$ formHelper-&gt; 结束($ form))?&gt; 
&lt; / div&gt; 
   
 
 

另一个模板的代码,Form / Order / form.html.php, 是

 &lt;?php 
 / ** 
 * @var \ Symfony \ Bundle \ FrameworkBundle \ Templating \ TimedPhpEngine $ view 
 * @var \ Symfony \ Bundle  \ FrameworkBundle \ Templating \ Helper \ FormHelper $ formHelper 
 * @var \ Symfony \ Component \ Templating \ Helper \ SlotsHelper $ slotsHelper 
 * @var \ Symfony \ Component \ Form \ FormView $ form 
 * / 
 $ formHelper  = $ view ['form']; 
 $ slotsHelper = $ view ['slots']; 
 $ view-&gt; extend(':Form:form.html.php'); 
 
 $ slotsHelper-  &gt; start('form-widget'); 
echo $ formHelper-&gt; widget($ form); 
 $ slotsHelper-&gt; stop(); 
   
 
 <  p>在Controller中,我正在渲染表单,因为我已经呈现了一个表单: 
 
 
  $ this-&gt; render(“Form / Order / form.html  .php“,['form'=&gt;  $ orderForm-&gt; createView()])
   
 
 

如果我用“返回的字符串”更改此句子,Symfony只打印此“返回的字符串”,而不是标题 。

表单是正确呈现的,但由于某种原因我无法理解,Symfony正在打印HTTP标题。

谢谢!

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题