2017-03-17 3 views
0

が見つかりませルートはhttp://knpuniversity.com/screencast/symfony/ からの私の最初のアプリをやっていないことは、スタンダールのエラーですが、私はそれをデバッグする方法がわからない、debug:errorルート/genus/{genusName}で原因がSymfony2の:「GET /属/タコ/」

存在しています

のrouting.yml(genus/{genusName}/notesがうまく機能している)

app: 
    resource: '@AppBundle/Controller/' 
    type: annotation 

のsrc/AppBundle /コントローラ/ GenusController.php

<?php 
namespace AppBundle\Controller; 
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; 
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 
use Symfony\Bundle\FrameworkBundle\Controller\Controller; 
use Symfony\Component\HttpFoundation\JsonResponse; 
use Symfony\Component\HttpFoundation\Response; 
class GenusController extends Controller 
{ 
    /** 
    * @Route("/genus/{genusName}") 
    */ 
    public function showAction($genusName) 
    { 
     return $this->render('genus/show.html.twig', array(
      'name' => $genusName, 
     )); 
    } 
    /** 
    * @Route("/genus/{genusName}/notes", name="genus_show_notes") 
    * @Method("GET") 
    */ 
    public function getNotesAction($genusName) 
    { 
     $notes = [ 
      ['id' => 1, 'username' => 'AquaPelham', 'avatarUri' => '/images/leanna.jpeg', 'note' => 'Octopus asked me a riddle, outsmarted me', 'date' => 'Dec. 10, 2015'], 
      ['id' => 2, 'username' => 'AquaWeaver', 'avatarUri' => '/images/ryan.jpeg', 'note' => 'I counted 8 legs... as they wrapped around me', 'date' => 'Dec. 1, 2015'], 
      ['id' => 3, 'username' => 'AquaPelham', 'avatarUri' => '/images/leanna.jpeg', 'note' => 'Inked!', 'date' => 'Aug. 20, 2015'], 
     ]; 
     $data = [ 
      'notes' => $notes 
     ]; 
     return new JsonResponse($data); 
    } 
} 

アプリ/リソース/ビュー/属/ show.html.twig

{% extends 'base.html.twig' %} 
{% block title %}Genus {{ name }}{% endblock %} 
{% block body %} 
    <h2 class="genus-name">{{ name }}</h2> 
    <a href="{{ path('genus_show_notes', {'genusName': name}) }}">Json Notes</a> 
    <div class="sea-creature-container"> 
     <div class="genus-photo"></div> 
     <div class="genus-details"> 
      <dl class="genus-details-list"> 
       <dt>Subfamily:</dt> 
       <dd>Octopodinae</dd> 
       <dt>Known Species:</dt> 
       <dd>289</dd> 
       <dt>Fun Fact:</dt> 
       <dd>Octopuses can change the color of their body in just three-tenths of a second!</dd> 
      </dl> 
     </div> 
    </div> 
    <div class="notes-container"> 
     <h2 class="notes-header">Notes</h2> 
     <div><i class="fa fa-plus plus-btn"></i></div> 
    </div> 
    <section id="cd-timeline"></section> 
{% endblock %} 

デバッグ:ルートhttp://joxi.ru/Dr8j6YniOx3E26(申し訳ありませんが、私は評判のURLのみ原因を貼り付けることができます)

答えて

1

あなたのルートでパス構成にスラッシュが含まれていません。あなたのサンプルを動作させるには、コントローラにアクセスするときに末尾のスラッシュ(たとえば/genus/octopus/ではなく/genus/octopus)を削除するか、ルート設定にスラッシュを追加する必要があります。

+0

ああ、そう簡単!ありがとう! – SidSpears

関連する問題