2012-12-31 92 views
0

驗證似乎導致的傳遞到樹枝文件信息丟失:的Symfony驗證失去樹枝參數

「變量‘MORE_THAN_ONE’不存在ormedormedBundle:同意:在line new.html.twig 15」

有沒有一種設置可以在驗證中保存這些數據?

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); 
    } 

枝條file:

{% 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 %} 

回答

0

同事說:

您還需要在控制器中傳遞該變量create操作。問題解決了。