2
私は私のコントローラに非既存の変数を処理しようとしている
たデータベースはすべての変数なしのビューを返します空の場合:小枝 `それが印刷されていないにも関わらず、エラーをexist`ない変数
if(!$votes->findOneById(1) || !$images->findOneById(1)){
return $this->render('admin/stats_and_images.html.twig');
}
return $this->render('admin/stats_and_images.html.twig', [
'images' => $images->countVotesForAllImages(),
'image_podium' => $images->getTopNImages(3),
'form' => $form->createView(),
'votesToday' => $votes->votesToday(),
'votesMonth' => $votes->votesMonth(),
'votesTotal' => $votes->votesTotal()
]);
をと
:私はこれを取得しています定義する3つのフィールドすべての厳格な要件にもかかわらず{% if (votesTotal[0][1] is defined) and (votesToday[0][1] is defined) and (votesMonth[0][1] is defined) %} <div class="col-md-6"> <h4 class="sub-section--header">Liczba Oddanych Głosów:</h4> <hr> <p> <div class="col-sm-6"> Dzisiaj: <span class="text-info large-num">{{ votesToday[0][1] }}</span> </div> <div class="col-sm-6"> Ten miesiąc: <span class="text-info large-num">{{ votesMonth[0][1] }}</span> </div> </p> <p> <strong>Głosów ogółem: </strong><span class="text-info large-num">{{ votesTotal[0][1] }}</span> </p> </div> <div class="col-md-6"> <h4 class="sub-section--header">Wygrywające zdjęcia:</h4> <p class="text-muted">Ten miesiąc</p> <hr> <div class="row text-center"> <div class="col-md-4"> <a href="{{ asset("uploads/"~image_podium[0][0].fileName) }}" target="blank"> <img src="{{ asset("uploads/"~image_podium[0][0].fileName) | imagine_filter('my_thumb') }}" alt="{{image_podium[0][0].title}}" class="site-thumbnail" title="{{image_podium[0][0].title}} - {{image_podium[0][0].author}}"> </a> <p><strong>Głosów: {{image_podium[0]['votes']}}</strong></p> </div> <div class="col-md-4"> <a href="{{ asset("uploads/"~image_podium[1][0].fileName) }}" target="blank"> <img src="{{ asset("uploads/"~image_podium[1][0].fileName) | imagine_filter('my_thumb') }}" alt="{{image_podium[1][0].title}}" class="site-thumbnail" title="{{image_podium[1][0].title}} - {{image_podium[1][0].author}}"> </a> <p>Głosów: {{image_podium[1]['votes']}}</p> </div> <div class="col-md-4"> <a href="{{ asset("uploads/"~image_podium[2][0].fileName) }}" target="blank"> <img src="{{ asset("uploads/"~image_podium[2][0].fileName) | imagine_filter('my_thumb') }}" alt="{{image_podium[2][0].title}}" class="site-thumbnail" title="{{image_podium[2][0].title}} - {{image_podium[2][0].author}}"> </a> <p>Głosów: {{image_podium[2]['votes']}}</p> </div> </div> </div> {% else %} <h2 class="text-danger text-center"> No votes at the moment :) </h2> {% endif %}
しかし、それでもまだ:私の見解では、私はそうのような変数の不足に対処しようとしています
変数 "votesToday"は存在しません。
ビューの<span class="text-info large-num">{{ votesToday[0][1] }}</span>
部分を指しています。
なぜこれが起こっていますか?どのように避けることができますか?
Twigファイルに '{{dump(votesToday)}}'を追加して投稿を編集して、そのダンプを表示できますか? 'app_dev.php' URLを使ってやる必要があります。 –
キャッシュされたテンプレートを使用していないことを確認してください。あなたの[code](https://twigfiddle.com/bt168s)はそのまま動作します。 (ちょうどassest関数を削除し、fitlerを想像してください) – DarkBee
"votesToday"があなたに適切にタイプミスや特殊文字、またはsthを持っていない場合はうれしいでしょう。 –