Symfony验证失去了twig参数

时间:2012-12-31 18:54:12

标签: symfony

验证似乎会导致丢失传递给twig文件的信息:

'变量'more_than_one“ormedormedBundle中不存在:同意:第15行的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(Controller):

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

Twig文件:

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

1 个答案:

答案 0 :(得分:0)

Coworker说:

您还需要将该变量传递给控制器​​中的create动作。问题解决了。