0

検証により、twig ファイルに渡される情報が失われるようです。

「15 行目の ormedormedBundle:Consent:new.html.twig に変数 "more_than_one" が存在しません」

このデータを検証で保持する設定はありますか?

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

1 に答える 1

0

同僚は次のように述べています。

コントローラーの create アクションにもその変数を渡す必要があります。問題が解決しました。

于 2012-12-31T18:55:05.047 に答える