验证似乎会导致传递给树枝文件的信息丢失:
'变量“more_than_one”在第 15 行的 ormedormedBundle:Consent:new.html.twig 中不存在'
是否有在验证中保留此数据的设置?
BafflingPlayer(所有控制器使用的静态函数):
class BPCount extends Controller
{
public static function BafflingPlayers($ob, $id){
$em = $ob->getDoctrine()->getManager();
return $em->getRepository('lthrtlthrtBundle:BafflingProvider')
->numPlayers($id);
}
public static function numBP($ob, $id){
return count(BPCount::BafflingPlayers($ob, $id));
}
}
ConsentController.php(控制器):
public function newAction()
{
$em = $this->getDoctrine()->getManager();
$sc = $this->get('security.context');
$entity = new Consent();
$usor = $sc->getToken()->getUser();
$form = $this->createForm(new ConsentType()
,$entity
,array('attr'=>
array('securitycontext' => $sc
,'em' => $em
)));
return $this->render('lthrtlthrtBundle:Consent:new.html.twig', array(
'entity' => $entity
,'form' => $form->createView()
,'more_than_one' => BPCount::NumBP($this,$usor->getId()) > 1
));
}
Consent.php(实体):
public function isEndAfterBegin(){
return ($this->consentEnd > $this->consentBegin);
}
树枝文件:
{% extends "::layout.html.twig" %}
{% block subtitle %}Consent{% endblock subtitle %}
{% block body %}
<h1>Consent Edit</h1>
<form action="{{ path('consent_create') }}" method="post" {{ form_enctype(form) }}>
<div class="span12">
<span class="clear">
</span>
{#}
{% if is_granted('ROLE_ADMIN') %}
{#}
{% if is_granted('ROLE_ADMIN') or more_than_one %}
<span class="span12 clear">
<span class="span2">
{{form_label(form.Baffling_Player) }}
</span>
<span class="span6">
{{form_widget(form.Baffling_Player) }}
</span>
</span>
{% else %}
{% endif %}
<span class="span12 clear">
<span class="span2">
{{form_label(form.subject)}}
</span>
<span class="span6">
{{form_widget(form.subject)}}
</span>
</span>
<span class="span12 clear">
<span class="span2">
{{form_label(form.consentBegin) }}
</span>
<span class="span6">
{{form_widget(form.consentBegin) }}
</span>
</span>
<span class="span12 clear">
<span class="span2">
{{form_label(form.consentEnd) }}
</span>
<span class="span6">
{{form_widget(form.consentEnd) }}
</span>
</span
<span class="span12 clear">
<span class="span2">
{{form_label(form.given) }}
</span>
<span class="span6">
{{form_widget(form.given) }}
</span>
</span>
</div>
{{ form_errors(form) }}
{{ form_rest(form) }}
<p>
<button type="submit">Create</button>
</p>
</form>
<ul class="record_actions">
<li>
<a href="{{ path('caseload') }}">
Back to the list
</a>
</li>
</ul>
{% endblock body %}